不知道如何处理。应用程序在 getInputStream() 调用时崩溃。日志消息出现直到
HttpURLConnection conn = null;
try {
URL url = new URL(params[0]);
Log.d(params[0],"URL");
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("username", "password".toCharArray());
}
});
conn = (HttpURLConnection) url.openConnection();
Log.d("Afer conn", "Connection");
conn.setRequestMethod("GET");
Log.d("Afer conn", "Step1");
conn.setConnectTimeout(5000);
Log.d("Afer conn", "Step2");
//conn.connect();
return conn.getInputStream().toString();
} catch (MalformedURLException e) {
Log.d(e.getMessage(), "Error1");
return e.getMessage();
} catch (ProtocolException e) {
Log.d(e.getMessage(), "Error2");
return e.getMessage();
} catch (IOException e) { //It comes here
Log.d(e.getMessage(), conn.getErrorStream().toString());
conn.getErrorStream().toString();
return e.getMessage();
} catch ( Exception e ) {
Log.d(e.getMessage(), "Error4");
return e.getMessage();
}
出现在 IOException 块的消息是这样的:
Received authentication challenge is null
。
但是用户名和密码是正确的。