应用程序在getInputStream崩溃

时间:2012-09-12 04:02:16

标签: android crash connection

不确定如何处理此问题。应用程序在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

但是用户名和密码是正确的。

0 个答案:

没有答案