Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket connection from behind the Proxy Server

 
Reeti Saha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the smily face....
That should read "username:password"
:P
 
Reeti Saha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try out :
System.getProperties().setProperty("socksProxySet", "true");
System.getProperties().setProperty("socksProxyHost", proxyServerName);
System.getProperties().setProperty("socksProxyPort", proxyServerPort);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic