0

图书馆员方法返回 apache HttpResponse 对象。我需要获取重定向 Uri。我怎样才能做到这一点?

4

2 回答 2

2

我认为您可以使用 Location标题:

response.getLastHeader("Location").getValue();
于 2012-11-27T20:38:43.260 回答
1

要获得重定向 Uri,您必须做两件事:

  1. 设置重定向到您的 HttpClient 实例:

    HttpClient httpclient = getNewHttpClient(); HttpClientParams.setRedirecting(httpclient.getParams(), false); // 检测重定向所必需的

  2. 请求后从 HttpResponse 实例获取重定向 Uri:

    response.getLastHeader("位置").getValue();

于 2012-12-05T15:23:20.957 回答