1
我有下面的代碼。我得到HTTP響應代碼-1。只是爲了排除故障,我想知道在檢查http響應代碼之前是否應該等待連接一段時間後再等待。Android HttpUrlConnection響應等待時間
String requestURL = "https://www.google.com";
HttpURLConnection connection = new HttpURLConnection;
connection = (HttpURLConnection) requestUrl.openConnection();
connection.setConnectTimeout(20000);
connection.setReadTimeout(20000);
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.connect();
OutputStreamWriter writer = new OutputStreamWriter(this.connection.getOutputStream());
writer.write(getHttpData());
writer.flush();
writer.close();
if(connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new inputStreamReader(connection.getInputStream()));
}
Is getResponseCode()or getInputStream()blocking call?我是否過早閱讀回覆?我應該等一下嗎?
感謝您的幫助。你可能會得到的-1
怪異的HTTP響應代碼
@Marek它看起來像你改變的代碼是不正確的。答案的要點是羅伯託必須將'<'改成'<=' – 2013-02-08 15:07:46
@DrewLeSueur我很抱歉,謝謝你的注意 – 2013-02-08 15:21:46