views:

636

answers:

2

Hi,

I am trying to send a GET via Android's HttpURLConnection (which is an 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
+6  A: 

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.

Matthias
Hi Matthias, were you using the twitter api?
Moons
no I ran into this problem as part of the DefaultOAuthProvider implementation for Signpost, which uses HTTPUrlConnection instead of Apache HttpClient.
Matthias
And did you stick to Signpost? I'm having a lot of trouble with it on android.
Horia Dragomir
yes -- I developed it! This question is about a year old, meanwhile I added a CommonsHttpOAuthProvider which doesn't suffer from this issue. i.o.w. you can now use Signpost without any of the java.net classes, which are buggy in Harmony/Android.
Matthias
A: 

"Basic YWRtaW46YW RtaW4=" is right code for my address.I check on j2me project.

And on android my getbase64 method returns "Basic YWRtaW46YW RtaW4=" its true.

and ı use it on:

httpConnection.setRequestProperty("Authorization",getBase64Encode()); ==> "Basic "+Base64.Decode(name:pass);

Finally responce code is 401

any idea???

atasoyh