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);

Share and Enjoy:
  • del.icio.us
  • Reddit
  • Facebook
  • Identi.ca
  • TwitThis

Related posts:

  1. Java Date and Calendar classes
  2. JSR-310
  3. Language Limbo
  4. Brain dump

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Search