• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Socket connection from behind the Proxy Server

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try out :
System.getProperties().setProperty("socksProxySet", "true");
System.getProperties().setProperty("socksProxyHost", proxyServerName);
System.getProperties().setProperty("socksProxyPort", proxyServerPort);
 
Maybe he went home and went to bed. And took this tiny ad with him:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic