How do I use a proxy server for HTTP requests?
When a Java applet under the control of a browser ,such as Netscape or Internet Explorer fetches content via a URLConnection, it will automatically and transparently use the proxy settings of the browser.
If we\'re writing an application, however, we\'ll have to manually specify the proxy server settings. we can do this when running a Java application, or we can write code that will specify proxy settings automatically for the user (providing we allow the users to customize the settings to suit their proxy servers).
To specify proxy settings when running an application, use the -D parameter :
jre -DproxySet=true -DproxyHost=myhost -DproxyPort=myport MyApp
Alternately, our application can maintain a configuration file, and specify proxy settings before using a URLConnection :
// Modify system properties
Properties sysProperties = System.getProperties();
// Specify proxy settings
sysProperties.put(\"proxyHost\", \"myhost\");
sysProperties.put(\"proxyPort\", \"myport\");
sysProperties.put(\"proxySet\", \"true\");