我是新來的黑莓應用程序的開發。我有一個愚蠢的錯誤,而在HttpConnection
在httpcon.getResponseCode()
方法給源找不到錯誤。來源
請,任何一個可以弄清楚這個錯誤?
這裏是我的方法:
net.rim.device.api.io.transport.ConnectionFactory cf = new net.rim.device.api.io.transport.ConnectionFactory();
httpConn = (HttpConnection) cf.getConnection(url).getConnection();
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Confirguration/CLDC-1.0");
httpConn.setRequestProperty("Accept_Language", "en-US");
httpConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
httpConn.setRequestProperty("Content-Length",
Integer.toString(postData.length));
os = httpConn.openOutputStream();
os.write(("[email protected]&Password=yah123")
.getBytes("UTF-8"));
os.flush();
os.close();
try {
responseCode = httpConn.getResponseCode();
} catch (IOException ex1) {
//check if it's eof, if yes retrieve code again
if (-1 != ex1.getMessage().indexOf("EOF")) {
try {
responseCode = httpConn.getResponseCode();
} catch (IOException ex2) {
System.out.println(ex2.getMessage());
// handle exception
}
} else {
System.out.println(ex1.getMessage());
// handle exception
}
}
int status = httpConn.getResponseCode();
if (status == HttpConnection.HTTP_OK) {
InputStream input = httpConn.openInputStream();
byte[] bytes = IOUtilities.streamToBytes(input);
StringBuffer raw = new StringBuffer(new String(bytes));
raw.insert(0, "bytes received]\n");
raw.insert(0, bytes.length);
raw.insert(0, '[');
url = raw.toString();
input.close();
} else {
url = "response code = " + status;
}
httpConn.close();
} catch (IOCancelledException e) {
System.out.println(e.toString());
return "";
} catch (IOException e) {
return "";
}
return "";
}
更新:我不想踏進getResponseCode()
。 Eclipse正在停止執行,並顯示Source Not Found錯誤。
什麼是你想怎麼辦?這是一個**編譯**錯誤,或者你是否試圖在調試器中進入一個方法? – Nate
@Nate是的,我們是一步進入方法當時只有我們正在運行時間Error.Error顯示當'Getresponsecode()被調用'。 – RajeshKdev
@Nate我發現我的錯誤。當調用'HttpConnection。 getResponseCode()'在那個URL字符串中我們必須添加'deviceside = true',那麼只會調用'getresponsecode()'而不會拋出任何http異常。例如:'httpClient ht = new httpClient(); 字符串str = ht.getHttpClientResponse( 「HTTPS://www.google.co.in;裝置側=真」,後);' – RajeshKdev