Hi in my android application I am using HttpUrlconnection for web services. So for any web resource request with response 401 it's not giving any header fields or response code.And it showing content length -1.It Fires exception java.io.IOException: Received authentication challenge is null
. Now my problem is that how to check response code for such conditions. Need Help. I check those request in rest clients and there I found that my response coming properly with header response code with 401 and other fields also
My request looks like
String urlString ="http://WWW.ABC.com";
URL url = new URL(urlString);
login_urlConnection = (HttpURLConnection) url.openConnection();
login_urlConnection.setRequestMethod("GET");
int statusCode = login_urlConnection.getResponseCode() // Here I am getting exception I want this status code to check authentication failure
How to solve this problem. Need Help. Thank you.
I did same call with HttpClient and then I am able to get response code then why not with HttpUrlConnection. Am I doing something wrong Need Help.