当没有位置标题发送时从http响应中获取URL
问题描述:
当与http进行通信时,我需要获取从请求中生成的URL。当没有位置标题发送时从http响应中获取URL
我已经从http响应消息中打印出了标题及其值,但没有位置标题。我怎样才能获得这个网址? (我使用的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();
编辑:我不得不做一些小的调整,但经我测试上述作品。
你怎么能够发现这一点?我正在使用.getAllHeaders()函数并将它们全部打印出来,并且未列出位置标题。 – joepetrakovich 2010-11-02 02:01:27
@Petra,使用LiveHttpHeaders和Firebug。我会很快发布一个例子。你使用的是哪个版本的HttpClient? – 2010-11-02 02:02:03
Android 2.2上的org.apache.http.client模块 – joepetrakovich 2010-11-02 02:08:58