I'm looking how to follow redirects for POST requests as POST in Apache HttpClient 5.1
By default, only GET requests resulting in a redirect are automatically followed. If a POST requests is answered with either HTTP 301 (Moved Permanently) or with 302 (Moved Temporarily) – the redirect is not automatically followed. This is specified by the HTTP RFC 2616
There are usecases, however, when POST request has to be redirected as POST. In such cases, the default behavior has to be changed in order to relax the strict HTTP specification.
With Apache HttpClient 4.5 this could be easily achieved by replacing DefaultRedirectStrategy with LaxRedirectStrategy or with your own custom implementation of RedirectStrategy interface. Examples:
- Apache HttpClient 4.5 redirect POST request to GET request
- https://www.baeldung.com/httpclient-redirect-on-http-post
In Apache HttpClient 5.1 this doesn't work anymore. The RedirectStrategy interface changed and no longer contain getRedirect method, LaxRedirectStrategy implementation has also been removed.
Is there a way to override default POST redirect behavior in Apache HttpClient 5.1 similar or as simple as in HttpClient 4.5?