Daniel C. Sobral Daniel C. Sobral - 1 year ago 224
Java Question

Apache HttpClient 4.1 - Proxy Authentication

I've been trying to configure the user and password for proxy authentication from the configured properties while using Apaches HttpComponent's httpclient, but with no success. All examples I have found refer to methods and classes that are no longer available, such as


So, can anyone give me an example of how to configure the proxy credentials?

Answer Source

For Basic-Auth it looks like this:

DefaultHttpClient httpclient = new DefaultHttpClient();
    new AuthScope("PROXY HOST", 8080),
    new UsernamePasswordCredentials("username", "password"));

HttpHost targetHost = new HttpHost("TARGET HOST", 443, "https");
HttpHost proxy = new HttpHost("PROXY HOST", 8080);

httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

AFAIK NTLM is not supported out of the box. But you might be able to manage that using NTCredentials and maybe overloading DefaultProxyAuthenticationHandler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download