Android 应用程序在getInputStream上崩溃
不知道该怎么处理。应用程序在getInputStream()调用时崩溃。日志消息将一直显示到Android 应用程序在getInputStream上崩溃,android,crash,connection,Android,Crash,Connection,不知道该怎么处理。应用程序在getInputStream()调用时崩溃。日志消息将一直显示到 HttpURLConnection conn = null; try { URL url = new URL(params[0]); Log.d(params[0],"URL"); Authenticator.setDefault (new Authenticator() {
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块上显示的消息如下:
收到的身份验证质询为空
但是用户名和密码是正确的。检查响应代码。它以前就在那里。但这没用。它在getResponseCode行崩溃:(您是否检查了您的参数[0]是否在浏览器中工作?是的,已检查。如果这是一个Android应用程序,您是否应该使用Apache HTTP客户端而不是URLConnection?