/** * A simple example that uses HttpClient to execute an HTTP request * over a secure connection tunneled through an authenticating proxy. */ public class ClientProxyAuthentication {
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("localhost", 8888), new UsernamePasswordCredentials("squid", "squid")); credsProvider.setCredentials( new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider).build(); try { HttpHost target = new HttpHost("httpbin.org", 80, "http"); HttpHost proxy = new HttpHost("localhost", 8888);