Retrieving a URL from an HTTP response when sending a location header

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

I printed the headers and their values ​​from the http response message, but there is no location header. How can I get this URL? (I am using HttpClient)

+5
source share
1 answer

It should look like:

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

EDITOR: I had to do a couple of tricks, but I tested, and it all works.

+12
source

All Articles