嗨,我尝试从千禧年媒体发出 GET 请求,让广告显示在我的黑莓 Java 应用程序中,但我似乎无法让它工作。这就是我所拥有的
HttpConnection conn = null;
InputStream in = null;
StringBuffer buff = new StringBuffer();
String result = "";
String url ="http://ads.mydas.mobi/getAdapid=157899&auid=ddd25abbb993f79454b12827c803fbafab2ad89b&ua"; try {
conn = (HttpConnection) new ConnectionFactory().getConnection(url).getConnection(); conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Confirguration/CLDC-1.0");
if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
// parser.parse(in, handler);
buff.append(IOUtilities.streamToBytes(in));
result = buff.toString();
} else {
result = "Error in connection" + conn.getResponseCode();
((SettingWaitScreen)screen).update(result);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
conn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
我不知道这是否是正确的方法,非常感谢您对执行此广告请求的任何帮助。这是我从网站http://docs.millennialmedia.com/S2S/ad-request.html得到的