Closed GoogleCodeExporter closed 8 years ago
View should have these additional methods:
doRetry()
doRedirect(URL)
Original comment by subwiz
on 2 Apr 2008 at 11:08
The ever helpful Oleg of HTTP Client mailed this in response to the query
(asked by
someone else, not me) in the HTTP Client mailing list:
** To get final request location:
--------
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("https://localhost/");
HttpContext context = new BasicHttpContext();
HttpResponse response = httpClient.execute(httpget, context);
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
HttpUriRequest request = (HttpUriRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
System.out.println(request.getURI());
--------
** To get all intermediate redirect locations:
--------
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.setRedirectHandler(new DefaultRedirectHandler() {
@Override
public URI getLocationURI(HttpResponse response, HttpContext
context) throws ProtocolException {
URI uri = super.getLocationURI(response, context);
System.out.println("redirect - > " + uri);
return uri;
}
});
HttpGet httpget = new HttpGet("https://localhost/");
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
--------
Original comment by subwiz
on 11 Nov 2008 at 5:55
FYI, that code for determining the final request location is actually incorrect
now,
with the latest HttpClient. Here's the new way to do it:
RequestWrapper requestWrapper = (RequestWrapper) context.getAttribute
(ExecutionContext.HTTP_REQUEST);
HttpUriRequest request = (HttpUriRequest)requestWrapper.getOriginal();
String finalUrl = request.getURI().toString();
Original comment by matthewl...@gmail.com
on 16 Apr 2009 at 8:00
Thanks for letting me know! I will do a set of tests and fix it.
Original comment by subwiz
on 17 Apr 2009 at 1:15
[Issue: 94] Reported similar problem.
Original comment by subwiz
on 15 Oct 2009 at 4:49
Original issue reported on code.google.com by
subwiz
on 27 Mar 2008 at 1:01