I am using HttpClient to do Post request to a server URL. The server URL is redirecting me and seems like my HttpClient is getting redirected automatically. I wanted to intercept the redirect response 302. I am unable to use setFollowRedirects(false). I wanted to know if there is anyway to do intercept the 302 response and stop Auto redirection?? I saw that we can achieve this using HttpURL Connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setFollowRedirects(false);
However I want to use HttpClient and HttpPost to avoid huge changes in my current implementation. Is there any way to achieve the same?
ResponseHandler.handleResponse(HttpResponse response)is part of theHttpClientclass.Also most of the
HttpClient.executemethods return anHttpResponse. UseHttpResponse.getStatusLine().getStatusCode().Also look at
org.apache.http.client.RedirectHandler.