Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request of webclient : getRedirectedUri() #1149

Closed
purplepapa opened this issue Jan 25, 2019 · 1 comment
Closed

Feature Request of webclient : getRedirectedUri() #1149

purplepapa opened this issue Jan 25, 2019 · 1 comment
Assignees
Milestone

Comments

@purplepapa
Copy link

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.

@slinkydeveloper slinkydeveloper self-assigned this Jun 6, 2019
@slinkydeveloper slinkydeveloper added this to the 3.8.0 milestone Jun 6, 2019
@slinkydeveloper
Copy link
Member

I've opened a pr for it: #1291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants