Skip to content

HttpConnection with Proxy

April 1, 2009

After lots of hunting got it right finally:

  URL url = new URL("");
        InetSocketAddress inet = new InetSocketAddress("", 8080);
        HttpURLConnection connection = ( HttpURLConnection ) url.openConnection( new Proxy(Proxy.Type.HTTP , inet));
        String proxyUser = "user" ;
        String proxyPassword = "pass" ;
        Properties p  =System.getProperties();
                   (new StringBuilder("Basic ")).
                            append((new BASE64Encoder()).encode((new StringBuilder(String.valueOf(proxyUser)))

            connection.setDoInput( true );
            connection.setDoOutput( true );
                "Content-Type", "text/xml; charset=" +
             XmlRpcMessages.getString( "XmlRpcClient.Encoding"));

             DataInputStream dis  = new DataInputStream(connection.getInputStream());
             byte []b = new byte[1];
             while (  -1 !=,0,1))
                 System.out.print(new String(b));

Set the following in java opts to specify proxy settings:





No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: