Skip to content Skip to sidebar Skip to footer

Httpclient Redirect Handler

I'm trying to call a web server that is using relative URL redirects for some of the calls. This of course isn't working with DefaultHttpClient as it isn't treating it as a relativ

Solution 1:

Have a look here: HttpClient 4 - how to capture last redirect URL

I would try getStatusLine() for start.

Solution 2:

My solution is to read location headers and follow them. This helped me:

if (statusCode != HttpStatus.SC_OK) {
    Header[] headers = response.getHeaders("Location");

    if (headers != null && headers.length != 0) {
        String newUrl = headers[headers.length - 1].getValue();
        // call again the same downloading method with new URLreturn downloadBitmap(newUrl);
    } else {
        returnnull;
    }
}

More in my post - Follow 302 redirects with AndroidHttpClient

Post a Comment for "Httpclient Redirect Handler"