Skip to content

Instantly share code, notes, and snippets.

@Madhuka
Created August 27, 2012 12:29
Show Gist options
  • Save Madhuka/3488018 to your computer and use it in GitHub Desktop.
Save Madhuka/3488018 to your computer and use it in GitHub Desktop.
proxy setting test for JVM
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class ProxyTest1 {
public static void main(String arg[]) {
System.out.println("Testing Proxy");
printProxyDetails();
// adding proxy details
System.out.println("Updating Proxy from Code");
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8083");
// testing for changes is done
printProxyDetails();
try {
URL url = new URL("http://www.google.lk");
URLConnection myURLConnection = url.openConnection();
myURLConnection.connect();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void printProxyDetails() {
System.out.println("HTTP Proxy Host"
+ System.getProperty("http.proxyHost"));
System.out.println("HTTP Proxy Port"
+ System.getProperty("http.proxyPort"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment