title: Get Response header when 401 occurred
body: <p>Hi I am working on android and java.So my problem is that whenever 401 occurred I am not able to get response header and also not able to get status code. I am using http url connection.
  My code looks like this:</p>
  
  <pre><code>String https_url = "http://abc.com";
        HttpsURLConnection con = null;
        int status;
        URL url;
        try {
  
           url = new URL(https_url);
           con = (HttpsURLConnection)url.openConnection();
  
           con.setDoInput(true);
           int responseCode = con.getResponseCode();   //throw IOException:Received authentication challenge is null
          if (responseCode == 200)
          {
  
          }
          else
          {
  
          }
        } catch (MalformedURLException e) {
           e.printStackTrace();
        } catch (IOException e) {
            Log.i("&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*", "inside exception");
            if (con != null) {
                Log.i("&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*", "inside not null");
            int responseCodeAfterException = con.getResponseCode();
            Log.i("&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*", "inside not null and response");
            Log.i("&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*&amp;*", "inside not null and response"+responseCodeAfterException);
            // Handle according to new response code
        }
           e.printStackTrace();
        }
  </code></pre>
  
  <p>I am not getting any field from response header. I know this is authentication problem and my server giving 401 in response but I am not able to get that response code. Am I doing anything wrong. How to handle this kind of exception. Need Help Thank you.</p>