未发送位置标头时从http响应中获取URL [英] Obtaining URL from http response when no location header is sent

查看:107
本文介绍了未发送位置标头时从http响应中获取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与http通信时, http://forecast.weather.gov/zipcity.php 我需要获取从请求生成的URL。

When communicating with http to http://forecast.weather.gov/zipcity.php I need to obtain the URL that is generated from a request.

我已从http响应消息打印出标题及其值,但没有位置标题。我如何获得此URL? (我正在使用HttpClient)

I have printed out the headers and their values from the http response message but there is no location header. How can I obtain this URL? (I'm using HttpClient)

推荐答案

它应该类似于:

HttpClient client = new DefaultHttpClient();
HttpParams params = client.getParams();
HttpClientParams.setRedirecting(params, false);
HttpGet method = new HttpGet("http://forecast.weather.gov/zipcity.php?inputstring=90210");
HttpResponse resp = client.execute(method);
String location = resp.getLastHeader("Location").getValue();

编辑:我不得不进行一些小调整,但我测试了以上工作。

I had to make a couple minor tweaks, but I tested and the above works.

这篇关于未发送位置标头时从http响应中获取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆