从黑莓模拟器打开http连接时出现问题

|| 从模拟器打开简单的HttpConnection时遇到了麻烦,我已经将deviceside = true后缀附加到了我的网址中,但是仍然无法正常工作,我收到了带有响应代码的空httpconnection的0。这是给我问题的代码:
public void readUrl(){
     HttpConnection conn=null;
        try {
            conn = (HttpConnection) Connector.open(\"http://www.google.com;deviceside=true\");
            conn.setRequestMethod(\"GET\");
             if(conn.getResponseCode()==HttpConnection.HTTP_OK){
                 System.out.println(\"Create connection sucessfully\");
             }

        } catch (ConnectionNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }




        DataInputStream din=null;
        ByteVector responseBytes=null;
        try {
            din = conn.openDataInputStream();
             responseBytes = new ByteVector();
              int i = din.read();
              while (-1 != i) {
                responseBytes.addElement((byte) i);
                i = din.read();
              }
        } catch (IOException e) {
            //TODO: HANDLE EXCEPTIONS
            e.printStackTrace();
        }
        responseBytes.toArray();
我不知道是怎么回事。它假定通过附加deviceside = true可以直接连接。无论如何,我也尝试安装MDS服务器并将URL设置为deviceside = false,但是结果是相同的。 现在,我使用本地URL(如http:// localhost:8080 / resources / mypage.html)测试了相同的代码,并且按预期方式工作,因此我想知道这是否可能是模拟器配置问题。我该如何解决? 非常感谢。     
已邀请:
以我的经验,使用MDS模拟器时需要附加; deviceside = true。在blackberry.com论坛上有一篇很棒的文章,向您展示如何确定应使用的连接后缀,以及有关在BlackBerry中使用连接的一些常规建议。 为了帮助您更轻松地获取请求的内容,可以使用IOUtilities类:
InputStream stream = conn.openInputStream();
String contents = new String(IOUtilities.streamToBytes(stream));
    
\“; deviceside = true \”用于直接TCP传输。要使用MDS传输,您需要附加\“; deviceside = false \”。 在设备模拟器上运行时,可以使用DIRECT TCP传输,而无需启动MDS模拟器。但是,如果要测试MDS传输,则需要先启动MDS模拟器,然后再启动设备模拟器。     
在模拟器设置选项卡的“常规”中,您是否选中了“使用模拟器启动MDS-CS”? 如果是这样,则根本不需要附加任何后缀...     
是的,您是对的,使用deviceside = true可以使用Internet连接,但是当我使用以下代码时,使用HttpConnection类似乎是一个问题:
public StreamConnection openConnection(){
    StreamConnection conn=null;
    try {
        conn = (StreamConnection) Connector.open(url+\";deviceside=true\");
        //conn.setRequestMethod(httpMethod);

    } catch (ConnectionNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }

    return conn;


}
它可以正常工作,所以我想知道...在Blackberry中打开连接时应该在其中放置我的代码以检查响应代码的问题。建立连接后?就像上面的代码一样,或者在打开dataStream之后像这样的代码:
din = conn.openDataInputStream();

         responseBytes = new ByteVector();
          int i = din.read();
          while (-1 != i) {
            responseBytes.addElement((byte) i);
            i = din.read();
          }
谢谢。     

要回复问题请先登录注册