Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Volley - Strange Error with HTTP code 401- java.io.IOException: No authentication challenges found

I meet this error when send a request and get back response with code 401:

com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found

Some people say that:
This error happens beause the server sends a 401 (Unauthorized) but does not give a "WWW-Authenticate" which is a hint for the client what to do next. The "WWW-Authenticate" Header tells the client which kind of authentication is needed (either Basic or Digest). This is usually not very useful in headless http clients, but thats how the standard is defined. The error occurs because the lib tries to parse the "WWW-Authenticate" header but can't. ( android - volley error No authentication challenges found )

But it's quite weird for me because I don't want to use WWW-authenticate things, I just want to get the code 401, but I always get the exception.

How can I bypass this problem? Any suggestion is really appreciated.

like image 352
imrhung Avatar asked May 27 '15 08:05

imrhung


1 Answers

I have do some research and come to conclusion that, this is a server issue, that did not follow the convention. From wiki:

401 Unauthorized (RFC 7235) Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.

I think the best way to solve this problem is to solve in the server by add the header (something like:

WWW-Authenticate: xBasic realm=""

For me, I cannot change the server, so I have to check the error message to detect that a 401 error:

if (error.getMessage().equalsIgnoreCase("java.io.IOException: No authentication challenges found")){
    showLoginError();
}

Not very elegant solution but work for now.

like image 138
imrhung Avatar answered Sep 27 '22 20:09

imrhung