There are two options under HTTP Request- Redirect Automatically and Follow Redirects. I want to implement behavior when Follow Redirects in unchecked
//CASE 1: HttpClient client = HttpClientBuilder.create().build();
//CASE 2: HttpClient client = HttpClientBuilder.create().disableRedirectHandling().build();
HttpGet get = new HttpGet("${request_link}");
HttpResponse response = client.execute(get);
SampleResult.setResponseData(EntityUtils.toByteArray(response.getEntity()));
I am using "disableRedirectHandling" as shown above in CASE 2 to stop auto re-direct. But I am getting a 200 response code instead of the expected 302.
This is response I get for CASE 1: Response code: 200 Response message: OK Response headers:
But I am expecting below reponse: Response code: 302 Response message: Found
Response headers: HTTP/1.1 302 Found Date: Fri, 11 Jun 2021 00:32:45 GMT Content-Length: 0 Connection: keep-alive Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 Location: {redirect location link}
Note: disableRedirectHandling() is disabling Redirect Automatically but what I want to implement is Disable Follow Redirects
Basically I want something of this setRedirectsEnabled(false) OR setMaxRedirects(0)
I tried this but no luck, Still getting re-direct
HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(RequestConfig.custom().setRedirectsEnabled(true).setMaxRedirects(0).build()).build();