Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

proxy server  RSS feed

 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to a webserver that uses a proxy server.

Tried the code below but keep geting the server error 407
the substitute the0.0.0.0 with the server ip address and username assword for my username and password

url = new URL("http://0.0.0.0/test/" + filename);
URLConnection connection = url.openConnection();
String password = "username assword";
String encodedPassword = b64c.encode(password);
connection.setRequestProperty( "Proxy-Authorization", encodedPassword);


InputStream is = url.openStream();


BufferedReader br = new BufferedReader(new InputStreamReader(is));
while( (record=br.readLine()) != null ) {
System.out.println(record);
}
is.close();
}
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felipe

You should try,
System.setProperty("http.proxyHost", "yourproxyserver.yourdomain.com");
System.setProperty("http.proxyPort", "yourproxyport");

Here is the link from sun forum,
http://forum.java.sun.com/thread.jspa?threadID=640068&tstart=135

The only issue with this is- it sets proxy in JVM System Property hence it ends up applying to ALL requests made after this setting..So you will have to remember to remove those property when done..

Regards
Maulin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!