javacodex.com
Java Examples
Java Examples
memu home questions

How to use an HTTP proxy in java?

Set in the command line:

   # java -Dhttp.proxyHost=myproxy -Dhttp.proxyPort=80 JavaClass

Specify a proxy in your source code:

System.setProperty("http.proxyHost", "myProxyServer.com");
System.setProperty("http.proxyPort", "80");
 

Specify use of system proxy in source code:

System.setProperty("java.net.useSystemProxies", "true");
 

Create a instance of proxy and pass it to the openConnection() method:

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("123.0.0.1", 8080));
URL url = new URL("http://www.yahoo.com");
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
uc.connect();
 

Questions answered by this page:

How do I configure proxy settings for Java? Java HTTP Proxy Settings HTTP Proxy setting in Java How to Set JVM Proxy Setting Without Touching the Code




Contact: javacodex@yahoo.com