You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using web client to get urls . I need to get the redirected uri for further parsing as base url . Thanks in advance . As I investigated, HttpAsyncClient uses a HttpContext to get it:
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().build();
try {
httpclient.start();
HttpClientContext localContext = HttpClientContext.create();
HttpGet request = new HttpGet("https://bit.ly/1eTpSHp");
request.setHeader("User-Agent", "gis");
Future<HttpResponse> future = httpclient.execute(request, localContext, null);
HttpResponse response = future.get();
String result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
System.out.println("Response: " + response.getStatusLine().getStatusCode() + ":" + result.length());
HttpHost target = localContext.getTargetHost();
List<URI> redirectLocations = localContext.getRedirectLocations();
for (URI u : redirectLocations) {
System.out.println("location: " + u.toASCIIString());
}
URI location = URIUtils.resolve(request.getURI(), target, redirectLocations);
System.out.println("Final HTTP location: " + location.toASCIIString());
// Expected to be an absolute URI
} finally {
httpclient.close();
}
just for reference.
The text was updated successfully, but these errors were encountered:
I am using web client to get urls . I need to get the redirected uri for further parsing as base url . Thanks in advance . As I investigated, HttpAsyncClient uses a HttpContext to get it:
just for reference.
The text was updated successfully, but these errors were encountered: