2012-09-14 6 views
7

Le credenziali di autenticazione sono impostate qui, tutto funziona perfettamente se l'utente/password forniti è corretto, ma si blocca se non sono corretti. Non è i problemi di server, ho controllato con Curl e browser, le credenziali non corrette restituiscono 401 subito .:Come evitare httpsURLConnection.getInputStream() in sospeso su Android se vengono fornite credenziali di accesso errate?

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

codice che pende è qui, si blocca su questa linea: a = new BufferedReader (nuovo InputStreamReader (httpURLConn. getInputStream())); (Nessuna eccezione, rimane solo su questa linea)

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

risposta

0

Potrebbe essere che il server è mantenere vivo (intestazione Keep-Alive) connessione?

+0

No, nessuna intestazione Keep-Alive nella risposta –

Problemi correlati