Sometimes, your network administrator may force you to connect to the internet through a HTTP Proxy. While this makes the administrator’s job of managing net security easier, a http proxy server will make your java application that communicates with the internet fall flat on its face.
If you are behind a proxy server, your java application must know that internet calls will go through a proxy, to do this, add the following lines to your program:
System.getProperties().put( “proxySet”, “true” );
System.getProperties().put( “proxyHost”, “server1″ );
System.getProperties().put( “proxyPort”, “8080″ );
Some proxies also require you to send a username and password, if your proxy requires such action then you must also add the following lines to your code:
URL url = new URL(“http://www.somedomain.com/”);
URLConnection conn = url.openConnection();
String password = “username:password”;
String encodedPassword = base64Encode( password );
conn.setRequestProperty( “Proxy-Authorization”, encodedPassword);
Related posts:





Leave a Reply