In Apache HttpClient 5's Fluent API, the Request can select a proxy while the Executor supplies its account. Execute the request through that credentialed object:

HttpHost proxy = new HttpHost("http", "proxy.example", 8080);
Executor executor = Executor.newInstance()
    .auth(proxy, proxyUser, proxyPassword.toCharArray());

String body = executor.execute(
        Request.get("https://www.example.com/").viaProxy(proxy))
    .returnContent()
    .asString();

Executor and Request are from org.apache.hc.client5.http.fluent; HttpHost is from org.apache.hc.core5.http. The account variables come from the application's configuration.

The two uses of proxy intentionally describe the same host and port. viaProxy chooses the route, while auth registers credentials for that intermediary with the Executor. If the final result remains 407, compare the selected route with the credential scope.

Calling a separate Request's convenience execute method would use another execution path. Keep the credentialed Executor attached to the operation, as in the example, so the client receiving the challenge has the configured account.

The example uses the 5.x char-array password interface. Older HttpClient 4 Fluent snippets use different packages and method signatures. Once the request completes, returnContent consumes the response entity and releases its connection for reuse.

Allakkat attuumassuteqartut