HttpComponents HttpClient
Jump to navigation
Jump to search
External
- http://hc.apache.org/httpcomponents-client-ga/
- tutorial http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html
Internal
Multithreaded Execution
In order to allow execution of multiple HTTP requests concurrently on multiple threads, httpclient must be equipped with a pooling connection manager such as PoolingClientConnectionManager.
Redirect Handling
Turn it off:
RedirectStrategy redirectStrategy = new RedirectStrategy() { @Override public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { return false; } @Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { throw new RuntimeException("getRedirect() NOT YET IMPLEMENTED"); } }; ... HttpClients.custom().setRedirectStrategy(redirectStrategy).build();
Troubleshooting
httpclient Automatically Follows Redirects
Sometimes this is not the behavior you want, for example when you try to get the OAuth token which is embedded in the redirect Location that you are supposed to parse. See Redirect Handling above.