https.proxyPortThe https.proxyPort system property sets the port number of the proxy server that the https protocol handler should use. It has no effect on its own, a proxy is only used when the https.proxyHost system property is also set. If https.proxyHost is set but https.proxyPort is not, the default port 443 is used.
Many proxy servers accept both HTTP and HTTPS (CONNECT) requests on the same port (for example 8080 or 3128), so you will often need to set https.proxyPort to the same value as http.proxyPort rather than relying on the default of 443.
The property is used by the default ProxySelector, so it applies to connections made with java.net.URL / HttpsURLConnection, and also to the java.net.http.HttpClient (Java 11+) when no explicit proxy selector has been set on the client builder.
Note:
https.proxyPortdoes not apply to HTTP URLsPlain
httpURLs use thehttp.proxyHostandhttp.proxyPortsystem properties instead. The default value ofhttp.proxyPortis80.
java -Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080 -jar app.jar
You can also set the proxy at runtime, but keep in mind that system properties are VM wide, so this will affect HTTPS connections made by all threads:
System.setProperty("https.proxyHost", "proxy.example.com");
System.setProperty("https.proxyPort", "8080");
https.proxyHost - the hostname or address of the HTTPS proxy server.http.proxyHost and http.proxyPort - the proxy server used for HTTP connections.http.nonProxyHosts - a | separated list of hosts that should be accessed directly, bypassing the proxy. Used for both HTTP and HTTPS connections.java.net.useSystemProxies - use the operating system's proxy settings.Here are some other networking Java system properties:
com.sun.net.ssl.checkRevocationcom.sun.security.enableCRLDPhttp.agenthttp.keepAlivehttp.maxConnectionshttp.nonProxyHostshttp.proxyHosthttp.proxyPorthttps.protocolshttps.proxyHostjava.net.preferIPv4Stackjava.net.preferIPv6Addressesjava.net.useSystemProxiesjavax.net.debugjavax.net.ssl.trustStorejdk.http.maxHeaderSizejdk.net.hosts.filejdk.tls.client.protocolsjdk.tls.server.newSessionTicketCountjdk.crypto.disabledAlgorithmsjdk.tls.disabledAlgorithmsnetworkaddress.cache.negative.ttlnetworkaddress.cache.ttlocsp.enablesun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeoutsun.net.inetaddr.ttlJava has supported the https.proxyPort system property since at least Java 1.4.
https.proxyPort on StartupYou can set the https.proxyPort java system property during startup of the java runtime using the -D command line argument:
java -Dhttps.proxyPort=8080 MyAppMain
You may also be able to specify https.proxyPort via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Dhttps.proxyPort=8080
https.proxyPort at RuntimeYou can set https.proxyPort at runtime with the following Java code:
System.setProperty("https.proxyPort", "8080");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the https.proxyPort system property may be cached within an internal private static variable of the implementing class.
To read the value of https.proxyPort at runtime, you can use this Java code:
String propertyValue = System.getProperty("https.proxyPort");
if (propertyValue != null) {
System.out.println("https.proxyPort = " + propertyValue);
} else {
System.out.println("https.proxyPort was null");
}