public static void main(final String[] args) throws Exception {
        try (final CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(CredentialsProviderBuilder.create()
                        .add(new HttpHost("httpbin.org", 80), "user", "passwd".toCharArray())
                        .build())
                .build()) {
            final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd");

            System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
            httpclient.execute(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 against
a target site that requires user authentication.
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java