I am configuring the client like this:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Now, I would like to tell my client not to use proxy for "localhost" or 127.0.0.1.
Thanks!
Hyper Text Transfer Protocol (HTTP) is a request/response protocol between clients and servers. The HTTP client is usually a web browser. The HTTP server is a remote resource that stores HTML files, images, and other content.
CloseableHttpClient is an abstract class which is the base implementation of HttpClient that also implements java. io. Closeable.
If you are processing HTTP responses manually instead of using a response handler, you need to close all the http connections by yourself.
Using HttpClient 4.3 APIs
HttpHost proxy = new HttpHost("someproxy", 8080);
HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy) {
@Override
public HttpRoute determineRoute(
final HttpHost host,
final HttpRequest request,
final HttpContext context) throws HttpException {
String hostname = host.getHostName();
if (hostname.equals("127.0.0.1") || hostname.equalsIgnoreCase("localhost")) {
// Return direct route
return new HttpRoute(host);
}
return super.determineRoute(host, request, context);
}
};
CloseableHttpClient client = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With