2012-09-14 13 views
7

Las credenciales de autenticación se establecen aquí, todo funciona perfectamente si el usuario/contraseña es correcta, pero se cuelga si son incorrectas. No son los problemas del servidor, he comprobado con Curl y navegador, credenciales incorrectas regresan 401 de inmediato .:Cómo evitar httpsURLConnection.getInputStream() en Android si se proporcionan credenciales de inicio de sesión incorrectas?

Authenticator.setDefault(new Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(user, password.toCharArray()); 
     } 
    }); 

Código que cuelga está aquí, se cuelga en esta línea: en = new BufferedReader (nuevo InputStreamReader (httpURLConn. getInputStream())); (Sin excepción, sólo se queda en esta línea)

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(); 
    } 

Respuesta

0

Podría ser que el servidor es mantener la conexión viva (encabezado Keep-Alive)?

+0

No, no cabecera Keep-Alive en la respuesta –

Cuestiones relacionadas