Reputation: 320
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?
Upvotes: 1
Views: 4219
Reputation: 8533
ResponseHandler.handleResponse(HttpResponse response)
is part of the HttpClient
class.
Also most of the HttpClient.execute
methods return an HttpResponse
. Use HttpResponse.getStatusLine().getStatusCode()
.
Also look at org.apache.http.client.RedirectHandler
.
Upvotes: 1