http - (HttpConnection) Connector.open(url) 与触摸电话

标签 http java-me touch midp httpconnection

我正在开发一个 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中添加此权限

  1. 右键单击项目

  2. 单击“属性”。

  3. 点击应用程序描述符

  4. 选择选项卡 API 权限

  5. 单击添加按钮并从列表中添加 javax.microedition.io.Connecter.http

希望对您有所帮助。

关于http - (HttpConnection) Connector.open(url) 与触摸电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9112246/

相关文章:

angular - Angular 2.0 中的 Http 请求和响应

c# - 上传照片并将其作为 json 对象发送

php - Web 服务器可以登录外部应用程序并将 cookie 传递给用户的浏览器吗?

blackberry - 有没有办法以编程方式从黑莓上最常用的列表中删除应用程序?

java - BlackBerry 线程模型

android - OnTouch 历史大小始终为 0

javascript - 名称为空的 Cookie - 这有效吗?

java - 蓝牙功能(通过 J2ME)

objective-c - 观察一次 Action 对多个 View 的触摸

Delphi 2010 平板电脑支持