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 new HttpRoute(host);
}
return super.determineRoute(host, request, context);
}
};
CloseableHttpClient client = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
source
share