首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(HttpConnection) Connector.open(网址)

(HttpConnection) Connector.open(网址)
EN

Stack Overflow用户
提问于 2012-02-02 12:22:59
回答 1查看 912关注 0票数 2

我正在处理一个J2ME应用程序,它发出一个HTTP请求,并相应地处理接收到的响应。

下面是我的HTTP请求代码

代码语言:javascript
复制
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触摸屏手机上查看它时,

代码执行到行。

代码语言:javascript
复制
hcon = (HttpConnection) Connector.open(url);

没有抛出任何异常,它最终会显示应用程序的第一个屏幕(主菜单)。

有什么限制或问题吗?

有解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2012-02-02 13:15:25

你在jad中添加了像这样的权限吗?

代码语言:javascript
复制
MIDlet-Permissions: javax.microedition.io.Connector.http

也可以通过以下步骤在netbean中添加此权限

点击Properties.

  • Click,Descripter

  • Select选项卡,API权限,

  • ,点击添加按钮,从列表中添加javax.microedition.io.Connecter.http

希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9112246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档