创建自定义 Apache HTTP 客户端重定向策略

Creating a Custom Apache HTTP Client Redirect policy

需要一点帮助,我听起来可能有点混乱..

我正在使用 Apache HTTP 客户端 4.5.1,我有一个 post url,一旦我们调用 post,它需要一些 header 来调用url 它 return 303 和一个 get url,但是根据 HTTP 客户端重定向策略,它会自动重定向 GET CALL 但它发送 header 也在重定向的 GET CALL 中。

如何覆盖 HTTP 客户端的重定向策略,以便 303 重定向在调用重定向 GET URL.

时不使用 header

知道如何实现这一点。我已经用重定向策略检查了几个选项。

罪魁祸首是 RedirectExec 请求执行拦截器中的 this line of code

通过使用自定义重定向策略

添加一些无害的虚拟请求header,应该能够防止它复制原始请求headers
CloseableHttpClient client = HttpClients.custom()
        .setRedirectStrategy(new DefaultRedirectStrategy() {

            @Override
            public HttpUriRequest getRedirect(
                    HttpRequest request,
                    HttpResponse response,
                    HttpContext context) throws ProtocolException {
                HttpUriRequest redirectRequest = super.getRedirect(request, response, context);
                redirectRequest.addHeader("x-custom", "stuff");
                return redirectRequest;
            }
        })
        .build();