0
HttpConnection c = null;
InputStream is = null;
StringBuffer sb = new StringBuffer();
String request = serverUrl; // + "?loc=" + location.getLat() + "," + location.getLng() + "data=" + message.getString();
try {
c = (HttpConnection) Connector.open("http://www.google.com");
c.setRequestMethod(HttpConnection.GET); //default
is = c.openInputStream(); // transition to connected!
int ch = 0;
for (int ccnt = 0; ccnt < 150; ccnt++) { // get the title.
ch = is.read();
if (ch == -1) {
break;
}
sb.append((char) ch);
return sb.toString();
}
} catch (IOException x) {
x.printStackTrace();
} finally {
try {
is.close();
c.close();
} catch (IOException x) {
x.printStackTrace();
}
}
System.out.println(sb.toString());
return null;
- 這條線(HttpConnection)Connector.open(「http://www.google.com」);不響應在上面的代碼
(HttpConnection) Connector.open("http://www.google.com");
不響應。我能做些什麼來解決這個問題?
應用程序是否正在掛起(等待)該線?它等待多久?它是否超時並拋出異常?你是在設備上還是在模擬器上測試這個?你確定設備/模擬器有良好的網絡連接嗎? – Nate 2013-02-10 04:32:58