Skip to content
Advertisement

Authenticated HTTP proxy with Java

How can I configure the username and password to authenticate a http proxy server using Java?

I just found the following configuration parameters:

JavaScript

But, my proxy server requires authentication. How can I configure my app to use the proxy server?

Advertisement

Answer

(EDIT: As pointed out by the OP, the using a java.net.Authenticator is required too. I’m updating my answer accordingly for the sake of correctness.)

(EDIT#2: As pointed out in another answer, in JDK 8 it’s required to remove basic auth scheme from jdk.http.auth.tunneling.disabledSchemes property)

For authentication, use java.net.Authenticator to set proxy’s configuration and set the system properties http.proxyUser and http.proxyPassword.

JavaScript
Advertisement