0

my java app needs to connect to the internet , I am behind a proxy server. i use the fallow functions to set proxy but it doesn't work?

System.getProperties().put("http.proxySet", "true");
System.getProperties().put("http.socksProxyHost", value);
System.getProperties().put("http.socksProxyPort", value);

thanks

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
ngh
  • 1
  • 1
  • 3

2 Answers2

0

Check out this question, especially the answer which uses Proxy class.

Community
  • 1
  • 1
dimoniy
  • 5,820
  • 2
  • 24
  • 22
  • I use PROXY class as fallows : Proxy proxy = new Proxy(Proxy.Type.SOCKS,newInetSocketAddress("127.0.0.1",15667)); url = new URL(siteAddress); httpUrlConnection = (HttpURLConnection) url.openConnection(proxy); but give this error :Malformed reply from SOCKS server and the my java app stop when url.openConnection(proxy); – ngh Nov 24 '13 at 11:27
0

Check the system parameter names. There are two ways you can do this:

  • Set the system parameter from the command line itself
java -Dhttp.proxyHost=proxyhostURL
-Dhttp.proxyPort=proxyPortNumber
-Dhttp.proxyUser=userName
-Dhttp.proxyPassword=password YourProgram

OR Set these parameter in the code as follows

System.getProperties().put("http.proxyHost", "proxyURL"); System.getProperties().put("http.proxyPort", "proxyPort"); System.getProperties().put("http.proxyUser", "userName"); System.getProperties().put("http.proxyPassword", "password");

Santosh
  • 17,667
  • 4
  • 54
  • 79