2012-09-14 9 views
7

Poświadczenia uwierzytelniające są ustawione tutaj, wszystko działa idealnie, jeśli podane hasło/hasło jest poprawne, ale zawiesza się, jeśli są niepoprawne. To nie problemy serwerów, sprawdziłem z Curl i Browser nieprawidłowe poświadczenia powrotu 401 od razu .:Jak uniknąć httpsURLConnection.getInputStream() na Androidzie, jeśli podane są niepoprawne dane logowania?

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

kodeksu, który wisi tu, to zawiesza się na tej linii: w = new BufferedReader (nowy InputStreamReader (httpURLConn. getInputStream())); (Nie jest wyjątkiem, że tylko pozostaje na tej linii)

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

Odpowiedz

0

Czy to możliwe, że serwer jest utrzymanie połączenia alive (Keep-Alive nagłówek)?

+0

Nie, bez nagłówka Keep-Alive w odpowiedzi –