Setting Proxy in Java Code

The java.net package contains classes that deal with connections across the network. If there is a direct connection to the Internet via a modem, various classes like the HttpConnection or the raw Connection class can be used to get a connection to a server on the net.

This approach fails if you are going through a proxy server. To tell the JVM a proxy is installed, system variables need to be set explicitly set using the System class.

What you have to do is basically set three variables. These are:

     proxySet    proxyPort    proxyHost


This small piece of code shows how to set a proxy before calling the connecting code:

 //some previous code    System.getProperties().put(

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: