public static void main(final String[] args) throws Exception {
        final CredentialsProvider credsProvider = CredentialsProviderBuilder.create()
                .add(new AuthScope("localhost", 8888), "squid", "squid".toCharArray())
                .add(new AuthScope("httpbin.org", 80), "user", "passwd".toCharArray())
                .build();
        final HttpHost target = new HttpHost("http", "httpbin.org", 80);
        final HttpHost proxy = new HttpHost("localhost", 8888);
        try (final CloseableHttpClient httpclient = HttpClients.custom()
                .setProxy(proxy)
                .setDefaultCredentialsProvider(credsProvider)
                .build()) {

            final RequestConfig config = RequestConfig.custom()
                .build();
            final HttpGet httpget = new HttpGet("/basic-auth/user/passwd");
            httpget.setConfig(config);

            System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() + " to " + target +
                    " via " + proxy);

            httpclient.execute(target, httpget, response -> {
                System.out.println("----------------------------------------");
                System.out.println(httpget + "->" + new StatusLine(response));
                EntityUtils.consume(response.getEntity());
                return null;
            });
        }
    }
A simple example that uses HttpClient to execute an HTTP request
over a secure connection tunneled through an authenticating proxy.
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java