Keep POST method after a 302 redirect response

163 views Asked by At

I am building a Junit test, in which I have to perform a HTTP Post to a Spring app. This app is secured by a CAS, so each request to this app is redirected to the CAS, which allow or not the request. If it does, a 302 response is sent. I configured my code to follow the redirection:

 CloseableHttpClient httpClient = HttpClientBuilder.create()
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .build();
            final HttpPost httpPost = new HttpPost(path);

httpPost.setHeader("Content-Type", "application/***+xml");
httpPost.setHeader("Authorization", "Basic ***");
httpPost.setEntity(new StringEntity(myObject.toString()));
CloseableHttpResponse response = httpClient.execute(httpPost);

The thing is that the POST request, when redirected, becomes a GET, which is not what I want. Is there a way avoid that ? By the way, when I perform the request with Postman, it works fine, and the POST is still a POST after the redirection

0

There are 0 answers