7
身份驗證憑證在此處設置,如果提供的用戶/密碼正確,則一切正常,但如果它們不正確則會掛起。這不是服務器的問題,我用捲曲和瀏覽器檢查,不正確的憑據返回401立刻意識到掛在這裏:如果提供不正確的登錄憑據,如何避免Android中的httpsURLConnection.getInputStream()掛起?
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
});
代碼,它掛在這條線:在=新的BufferedReader(新的InputStreamReader(httpURLConn。的getInputStream())); (沒有例外,它只是停留在這條線上)
try {
URL url = new URL(resourceUrl);
HttpURLConnection httpURLConn = (HttpURLConnection) url.openConnection();
String rawData = "";
String currentLine = null;
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(httpURLConn.getInputStream()));
while ((currentLine = in.readLine()) != null) {
rawData = rawData.concat(currentLine);
}
in.close();
} catch (UnknownHostException e) {
Log.i(CLASS_NAME + "::" + METHOD_NAME
, "An exception occured while reading data from remote host. httpURLConn.responseCode = " + httpURLConn.getResponseCode()
+ "/httpURLConn.responseMessage = " + httpURLConn.getResponseMessage(), e);
throw new UnknownHostException();
} catch (IOException e) {
Log.i(CLASS_NAME + "::" + METHOD_NAME
, "An exception occured while reading data from remote host. httpURLConn.responseCode = " + httpURLConn.getResponseCode()
+ "/httpURLConn.responseMessage = " + httpURLConn.getResponseMessage(), e);
throw new IOException();
}
沒有,響應中沒有Keep-Alive頭 –