Hello Everyone I've one application which opens a socket to connect and retrieve data from internet. Now my machine has gone behind a proxy server and I'm not able to connect to internet from my same old aplication. Can anyone pls. help me as how to solve this problem.. How can I provide the username and password to connect to the net. An example code will be highly appreciated. It's urgent. Regards Reeti
Banana Tower
Greenhorn
Joined: Nov 22, 2001
Posts: 5
posted
0
Try this( change proxyPort and proxyHost ) import sun.misc.BASE64Encoder; System.getProperties().put("proxySet","true"); System.getProperties().put("proxyHost",proxyHost); System.getProperties().put("proxyPort",proxyPort); String proxyAuthentication = "username assword"; String encodedPassword = "Basic " + new BASE64Encoder().encode(proxyAuthentication.getBytes()); URL url = new URL(someurl); URLConnection conn = url.openConnection(); conn.setRequestProperty("Proxy-Authorization",encodedPassword); I am new to Java but this works for java 1.3.0_02 Check out Javaworld.com tip #42 cheers, brian
Banana Tower
Greenhorn
Joined: Nov 22, 2001
Posts: 5
posted
0
Sorry about the smily face.... That should read "username:password" :P
Reeti Saha
Ranch Hand
Joined: Jun 26, 2001
Posts: 34
posted
0
Thanks for the reply, but I've already tried this, somehow this is not working. I don't want to make an URLConnection instead I want to open a socket connection. Would u pls. try to help me. Regards Reeti
Anirban Chatterjee
Greenhorn
Joined: Feb 06, 2001
Posts: 18
posted
0
try out : System.getProperties().setProperty("socksProxySet", "true"); System.getProperties().setProperty("socksProxyHost", proxyServerName); System.getProperties().setProperty("socksProxyPort", proxyServerPort);