I am trying to send a GET via Android\'s HttpURLConnection (imported from org.apache.harmony.luni.internal.net.www.protocol.http.
Just add this header to the request (in server side):
WWW-Authenticate: None
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.
Please note that there are two authentication approaches: HTTP Authentication and token-based authentication. If you are using HTTP Authentication then you have to follow referenced specification: include WWW-Authenticate header field on server side, use java.net.Authenticator locally, etc. If you are using token-based authentication then obviously you have to use cookies to store the token and make able to keep long lived sessions alive. In such case put the next code into android.app.Application.onCreate()
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
and you won't have troubles when receiving HTTP 401 from the server without WWW-Authenticate header field.
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).