从黑莓模拟器打开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)测试了相同的代码,并且按预期方式工作,因此我想知道这是否可能是模拟器配置问题。我该如何解决?
非常感谢。
没有找到相关结果
已邀请:
4 个回复
薄响
稀瓣囊
凸晴
勺的驴吓识
它可以正常工作,所以我想知道...在Blackberry中打开连接时应该在其中放置我的代码以检查响应代码的问题。建立连接后?就像上面的代码一样,或者在打开dataStream之后像这样的代码:
谢谢。