android 1.6 httpresponse 不包含位置标头
我有一个 android 1.6 应用程序,我正在尝试获取 HTTP GET 响应的位置标头。但是,当我调用 getLastHeader("location") 时,它返回 null。我什至通过调试器进入响应变量,并且没有发送位置标头。我需要在任意网站上执行此操作,但使用谷歌进行测试仍然会产生事故。我认为位置是要读取的默认标题? android 1.6不读取位置标头吗?我的代码如下:
HttpClient httpClient = DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://google.com");
try
{
HttpResponse response = httpClient.execute(httpGet);
if(response.getStatusLine().getStatusCode() == 200)
{
Header h = response.getLastHeader("location");
String location = h.getValue();
}
}
非常感谢帮助:)我要么寻找解决方案来获取位置,要么解释为什么我没有得到它:/
i have an android 1.6 application that i'm trying to get the location header of a HTTP GET response. however, when i call getLastHeader("location") it returns null. i even go into the response variable via debugger and there is no location header sent. i need to do this on an arbitrary site, but using google for testing purposes still produces the mishap. i thought location was a default header to be read? does android 1.6 not read the location header? my code is as followed:
HttpClient httpClient = DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://google.com");
try
{
HttpResponse response = httpClient.execute(httpGet);
if(response.getStatusLine().getStatusCode() == 200)
{
Header h = response.getLastHeader("location");
String location = h.getValue();
}
}
help is greatly appreciated :) i'm either looking for a solution to get the location or an explanation why i'm not getting it :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 HTTP RFC,第 14.30 点
因此,如果您的响应状态为 200,则不应设置 Location 标头,因此您的值为 null。
您还可以使用 Firebug 检查返回的标头进行检查。
From the HTTP RFC, Point 14.30
So if your response status is 200, the Location header should not be set, hence the null you have.
You can also check by using Firebug to check the header returned.