Hi, hope someone can help me with this.

I've written a pretty simple program that connect to a web page with the following code:

URL url = new URL(urlString);
URLConnection connection = url.openConnection();

This works fine at home where I am connected directly to the internet. Unfortunately, I am now trying to work on it at work, where we use a proxy to connect to the internet. I know the IP address and port of the proxy, but despite searching the net have been unable to track down how to configure my program to use the proxy. Most of the literature I have seen has been concerning WebStart and applets, neither of which is of use to me.

I found the following code on a site but it does not seem to want to work properly, going on about referencing a non-static method from a static context relating to the URL.openConnection().

System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "172.16.0.250", "myproxyname" );
System.getProperties().put( "3128", "80" );

URLConnection connection = URL.openConnection();
String password = "proxynameroxypassword";
String encodedPassword = base64Encode( password );
connection.setRequestProperty( "Proxy-Authorization", encodedPassword );


I'm not sure if this is the correct code. The IP and port of the proxy can be seen in the code above.

I'd be very grateful if someone could help me out with this.