Monday, 23 April 2018

android - No Authentication challenge found

I read a lot about this issue but I was not able to figure it out. I am using HttpURLConnection and it works fine, but on JellyBean where it throws the IOException: No Authentication challenge found when I call getResponseCode() in case of 401 even though the backend is sending in the response the correct headers:




HTTP/1.1 401 Unauthorized
WWW-Authenticate: realm="realm"


On the other hand, debugging it, I experienced something strange. I printed the headers value out on the console this way:



    Map> map = connection.getHeaderFields();
if (map != null) {
Set set = map.keySet();

for (String tmp : set) {
Log.i(LOG_TAG, tmp != null ? tmp : "null");
}
}


just before calling connection.getResponseCode(); and it stopped to throw that exception.



Any clue?




The connection is set up with the following values:



    connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Accept-Charset", "utf-8");
connection.setRequestProperty("Accept-Encoding", "gzip");

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...