Httpclient redirect handler

前端 未结 2 1541
礼貌的吻别
礼貌的吻别 2020-12-21 09:47

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

相关标签:
2条回答
  • 2020-12-21 10:22

    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 URL
            return downloadBitmap(newUrl);
        } else {
            return null;
        }
    }
    

    More in my post - Follow 302 redirects with AndroidHttpClient

    0 讨论(0)
  • 2020-12-21 10:48

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

    I would try getStatusLine() for start.

    0 讨论(0)
提交回复
热议问题