Httpclient 重定向处理程序
我正在尝试调用对某些调用使用相对 URL 重定向的 Web 服务器。这当然不适用于 DefaultHttpClient,因为它不将其视为相对 URL。我已经实现了 RedirectHandler 来尝试捕获重定向并添加到基本调用中,但我无法弄清楚如何获取重定向的位置。
使用以下方法如何找出我被重定向到的位置?我在响应或上下文中找不到任何包含我需要的字段,并且我不知道还能在哪里查找。
public URI getLocationURI(HttpResponse response, HttpContext context)
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 relative URL. I've gotten as far as implementing a RedirectHandler in an attempt to catch the redirect and add in the base call but I can't work out how to get the location of the redirect.
With the following method how do I go about finding out where I am being redirected to? I can't find any fields on either response or context that have what I need and I don't know where else to look.
public URI getLocationURI(HttpResponse response, HttpContext context)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
我的解决方案是读取位置标题并遵循它们。这对我有帮助:
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;
}
}
更多内容在我的帖子中 - 使用 AndroidHttpClient 进行 302 重定向< /a>
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
看看这里:HttpClient 4 - 如何捕获最后一个重定向 URL
我会尝试使用
getStatusLine()
开始。Have a look here: HttpClient 4 - how to capture last redirect URL
I would try
getStatusLine()
for start.