Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOException: "Received authentication challenge is null" (Apache Harmony/Android)

I am trying to send a GET via Android's HttpURLConnection (imported from org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection), and upon receiving the response, an IOException is thrown:

in doRequestInternal(): "Received authentication challenge is null"

What does this error mean, and what is causing this? I am writing OAuth parameters to the Authorization header, but I do this on other occasions, too, without problems.

    if (connection == null) {         connection = (HttpURLConnection) new URL(endpointUrl).openConnection();         connection.setRequestMethod("GET");     }      //... do some OAuth message signing      connection.connect();      int statusCode = connection.getResponseCode(); // throws IOException 
like image 504
Matthias Avatar asked Aug 31 '09 13:08

Matthias


2 Answers

I found out the reason.

First of all, to all who aren't aware of what this error means (I sure wasn't): This exception is thrown if the server replies with a 401. Very intuitive, considering that it was thrown in getResponseCode() (i.o.w. you are never able to check for 401s yourself, but have to catch this IOException instead...).

The actual cause for the 401 was that I didn't send an OAuth verifier code where it was expected at this point.

like image 129
Matthias Avatar answered Sep 23 '22 17:09

Matthias


Maybe will be useful for somebody...

This exception just means malformed answer headers: the "WWW-Authenticate" header was not found. Also, chunked answers with 401 code are not supported, so you'll need "Content-Length" header (can be zero).

like image 37
Vladimir Avatar answered Sep 19 '22 17:09

Vladimir