Java.Io.Ioexception:No Authentication Challenges Found

Why do I get android java.io.IOException: No authentication challenges found?

I thing problem in concatenation

i.e.

String basicAuth = "Basic " + Base64.encodeToString("mail@mail.com:123123".getBytes(), Base64.NO_WRAP);  
connection.setRequestProperty("Authorization", "basic " + basicAuth );

No need to bind "basic" with already encoded string (basicAuth).

Try to change with below code:

String basicAuth = "Basic " + Base64.encodeToString("mail@mail.com:123123".getBytes(), Base64.NO_WRAP);  
connection.setRequestProperty("Authorization",basicAuth);

I hope it work.

Volley: No authentication challenges found

Okay, I found a solution. The helper class contained an overriding getparams method, but no getheaders method. GET request requires getheaders, post requires getparams.

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

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.



Related Topics



Leave a reply



Submit