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

joe*_*ich 5 java http httpclient

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

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

Mat*_*hen 12

它应该类似于:

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();
Run Code Online (Sandbox Code Playgroud)

编辑:我不得不做一些小调整,但我测试和上述工作.