0

How do I get the final URL?
(The URL http://mz.cm/1gpgLAJ is redirected to https://moz.com/blog/announcing-mozcon-local-2016?utm_source=twitter&utm_medium=social&utm_content=announcing_mozcon_local_2016&utm_campaign=blog_post)

WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(
                        HttpClient.create().followRedirect(true)
                )).build()
                .get()
                .uri("http://mz.cm/1gpgLAJ")
                .exchangeToMono(clientResponse -> {
                    ....
                });

1 Answer 1

2

You can listen for redirect event with doOnRedirect. See below your example extended with doOnRedirect callback. More information about lifecycle callbacks you can find here.

WebClient.builder()
            .clientConnector(new ReactorClientHttpConnector(
                    HttpClient.create().followRedirect(true)
                        .doOnRedirect((res, conn) ->
                            System.out.println("Location header: " + res.responseHeaders().get("Location")))
            )).build()
            .get()
            .uri("http://mz.cm/1gpgLAJ")
            .exchangeToMono(clientResponse -> {
                ....
            });
Sign up to request clarification or add additional context in comments.

1 Comment

Is there any way to get the URL from ClientResponse?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.