System Proxy In Java Example
Chapter:
Networking
Last Updated:
21-09-2018 15:40:11 UTC
Program:
/* ............... START ............... */
public class JavaSystemProxy {
public static void main(String[] args) {
// The hostname, or address, of the proxy server used by the HTTP protocol handler.
System.setProperty("http.proxyHost", "proxy.domain.com");
// The port number of the proxy server used by the HTTP protocol handler.
System.setProperty("http.proxyPort", "8080");
// The hostname, or address, of the proxy server used by the HTTPS protocol handler.
System.setProperty("https.proxyHost", "proxy.domain.com");
// The port number of the proxy server used by the HTTPS protocol handler.
System.setProperty("https.proxyPort", "8080");
// print out system proxy settings
System.out.println("http.proxyHost: " + System.getProperty("http.proxyHost"));
System.out.println("http.proxyPort: " + System.getProperty("http.proxyPort"));
System.out.println("https.proxyHost: " + System.getProperty("https.proxyHost"));
System.out.println("https.proxyPort: " + System.getProperty("https.proxyPort"));
}
}
/* ............... END ............... */
Output
http.proxyHost: proxy.domain.com
http.proxyPort: 8080
https.proxyHost: proxy.domain.com
https.proxyPort: 8080
Notes:
-
If you want you can also add proxy settings programmatically use the same properties but this time set them using System.setProperty().
Tags
Java System Proxy, java use system proxy, java proxy settings environment variables, java https proxy, set proxy in java code