Last active
March 23, 2016 06:00
-
-
Save gary-liguoliang/9481416 to your computer and use it in GitHub Desktop.
Disable automatic redirect in HttpGet using HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HttpClient Version: 4.3.3 | |
RequestConfig requestConfig = RequestConfig.custom().setRedirectsEnabled(false).build(); | |
httpGet.setConfig(requestConfig); | |
CloseableHttpResponse response = httpClient.execute(httpGet); | |
System.out.println("Status Code: " + response.getStatusLine().getStatusCode()); | |
// Older version: http://stackoverflow.com/questions/1519392/how-to-prevent-apache-http-client-from-following-a-redirect | |
// HTTP parameters stores header etc. | |
HttpParams params = new BasicHttpParams(); | |
params.setParameter("http.protocol.handle-redirects",false); | |
httpget.setParams(params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment