Monday, April 23, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...