Naveen Metta
Mar 1, 2024

--

Thank you for pointing out that detail. You are correct; the default redirection policy for the newHttpClient() method in the HttpClient class is set to Redirect.NEVER according to the Javadoc. I appreciate your diligence in catching that discrepancy. If developers want to enable automatic following of redirects, they should explicitly set the redirection policy using the followRedirects method during the creation of the HttpClient instance, as demonstrated in the provided example:

HttpClient client = HttpClient.newBuilder()

.followRedirects(Redirect.NORMAL)

.build();

This allows for better control over the redirection behavior in HTTP requests. If you have any further questions or if there's anything else you'd like clarification on, feel free to ask!

--

--

Naveen Metta
Naveen Metta

Written by Naveen Metta

I'm a Full Stack Developer with 3+ years of experience. feel free to reach out for any help : mettanaveen701@gmail.com

No responses yet