¿Cómo evitar httpsURLConnection.getInputStream () en Android colgando si se proporcionan credenciales de inicio de sesión incorrectas?

Las credenciales de autenticación se establecen aquí, todo funciona perfectamente si el usuario / contraseña proporcionado es correcto, pero se bloquea si son incorrectos. No es el servidor de problemas, he comprobado con Curl y navegador, credenciales incorrectas devolver 401 de inmediato .:

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

El código que cuelga está aquí, se cuelga en esta línea: in = new BufferedReader (nuevo InputStreamReader (httpURLConn.getInputStream ())); (No hay 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(); } 

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.