我正在开发一个 J2ME 应用程序,它发出 HTTP 请求并根据收到的响应工作。
下面是我的 HTTP 请求代码
public String sendHttpGet(String url, String str) throws Exception {
HttpConnection hcon = null;
DataInputStream dis = null;
StringBuffer message = new StringBuffer();
try {
hcon = (HttpConnection) Connector.open(url);
dis = new DataInputStream(hcon.openInputStream());
int ch;
while ((ch = dis.read()) != -1) {
message.append((char)ch);
}
}catch(Exception e){
}finally {
if (hcon != null) {
hcon.close();
}
if (dis != null) {
dis.close();
}
MyForm.show();
}
return message.toString();
}
它在非触摸设备上工作正常,但当我在诺基亚 500 触摸手机上检查时,
代码执行到行
hcon = (HttpConnection) Connector.open(url);
没有抛出任何异常,它最终显示应用程序的第一个屏幕(主菜单)。
有什么限制或问题吗?
有什么解决办法吗?
最佳答案
你在jad中这样加过权限吗
MIDlet-Permissions: javax.microedition.io.Connector.http
或者您可以按照以下步骤在netbean中添加此权限
右键单击项目
单击“属性”。
点击应用程序描述符
选择选项卡 API 权限
单击添加按钮并从列表中添加
javax.microedition.io.Connecter.http
希望对您有所帮助。
关于http - (HttpConnection) Connector.open(url) 与触摸电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9112246/