Can someone point me to authoritative example that demonstrates use of Proxy with authentication.
My searches reveal varied examples not necessarily using ver. 4.3.6 and hence the confusion.
I encountered two approaches as following. I prefer NOT to set the proxy and credentials for every request and hence wondering whats the best practice here? Also I have to make sure this works for Basic, Digest and NTLM schemes.
Approach 1:
// Create client and set credential provider
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build();
// Every request is set the with proxy settings
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpGet httpget = new HttpGet("/");
httpget.setConfig(config);
Approach 2:
HttpHost proxyHost = new HttpHost(proxyServer, proxyPort);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
HttpClientBuilder clientBuilder = HttpClients.custom()
.setConnectionManager(connectionManager);
clientBuilder.setRoutePlanner(routePlanner);
client = clientBuilder.build();
// Where and how to set credentials as best practice ?
I am sure to get some heckling for this one but so far I have wondered too much hence asking some help. thanks,