Skip to content Skip to sidebar Skip to footer

Authentication Error When Using Httppost With Defaulthttpclient On Android

I'm running into a strange problem using HttpClient. I am using a DefaultHttpClient() with HttpPost. I was using HttpGet with 100% success but now trying to switch to HttpPost as t

Solution 1:

Authentication error: Unable to respond to any of these challenges: {}

This error message means that the server responded with 401 (Unauthorized) status code but failed to provide a single auth challenge (WWW-Authenticate header) thus making it impossible for HttpClient to automatically recover from the authentication failure.

Most likely application expects some soft of credentials in the HTML form enclosed in the HTTP POST request.

Solution 2:

Don't you have to declare the port and protocol? I'm just swagging this code so please don't be upset if it doesn't immediatley compile correctly. Also, I usually supply a UsernamePasswordCredentials to my setCredentials() but I imagine it's the same.

HttpHosthost=newHttpHost("www.foo.com", 443, "https");

// assemble your GET or POST

client.getCredentialsProvider().setCredentials(newAuthScope(host.getHostName(), host.getPort()));

HttpResponseresponse= client.execute(host, [HttpPost or HttpGet]);

More info about setCredentials here.

Solution 3:

Here's how I ended up with similar problem:

DefaultHttpClientclient=newDefaultHttpClient();
client.getCredentialsProvider().setCredentials(AuthScope.ANY,
            newUsernamePasswordCredentials(username, password));

Thanks to Ryan for right direction.

Solution 4:

Not specifying a Callback URL for my Twitter App resulted in the same error for me:

Authentication error: Unable to respond to any of these challenges: {oauth=WWW-Authenticate: OAuth realm="https://api.twitter.com"}

Setting a callback URL on Twitter fixed the problem

Post a Comment for "Authentication Error When Using Httppost With Defaulthttpclient On Android"