Java System Properties
Quick Reference Guide


https.proxyPort Java System Property

The https.proxyPort java system property specifies the port number of the proxy server used for HTTPS connections.

Default Value

443

Overview of https.proxyPort

The 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.proxyPort does not apply to HTTP URLs

Plain http URLs use the http.proxyHost and http.proxyPort system properties instead. The default value of http.proxyPort is 80.

Example

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");

Related Properties

Other Networking System Properties

Here are some other networking Java system properties:

References

Supported Since

Java has supported the https.proxyPort system property since at least Java 1.4.

Setting https.proxyPort on Startup

You 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

Setting / Reading https.proxyPort at Runtime

You 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 setProperty may 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");
}