未发送位置标头时从 http 响应获取 URL

发布于 2024-09-30 09:01:01 字数 215 浏览 2 评论 0原文

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

我已打印出 http 响应消息中的标头及其值,但没有位置标头。我怎样才能获得这个网址呢? (我使用的是HttpClient)

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙幽之幻 2024-10-07 09:01:01

它应该类似于:

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();

编辑:我必须进行一些小的调整,但我进行了测试并且上述工作正常。

It should be similar to:

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();

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文