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

Similar Programs Chapter Last Updated
Java URL Parts Example Networking 28-10-2016
Java Program To Create Socket At Specific Port Networking 28-10-2016
Java Find Proxy Settings Networking 10-09-2016
Java Download Webpage Example Networking 09-09-2016
Java URL Connection Date Networking 09-09-2016
Java Socket To Single Client Networking 09-09-2016
Java Server File Size Example Networking 09-09-2016
Java Multithreaded Server Example Networking 09-09-2016
Java Server File Modification Time Networking 09-09-2016
Java Connect To Server Example Networking 09-09-2016
Http Response Header In Java Example Networking 21-06-2016
Server Socket In Java Example Networking 30-04-2016
Socket Programming In Java Networking 30-04-2016
IP Address And HostName Of Local Computer In Java Networking 30-04-2016
HostName And IP Address In Java Networking 30-04-2016
Client Socket In Java Example Networking 30-04-2016
Read And Download Webpage In Java Example Networking 29-04-2016
Date Of URL Connection In Java Example Networking 29-04-2016
Who Is Lookup In Java Example Networking 21-07-2016
Port Scanner In Java Example Networking 21-07-2016
Ping IP Address In Java Example Networking 21-09-2018
MAC Address In Java Example Networking 22-09-2018
Get IP Address In Java Example Networking 07-04-2016
URL Properties In Java Example Networking 09-09-2016
Default URL Object In Java Example Networking 18-07-2016

1