User Tools

Site Tools


java:set-proxy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:set-proxy [2010/04/13 08:42] percyjava:set-proxy [2016/05/05 13:07] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== 在Java程序中如何设置代理 ======
  
 +
 +===== http代理设置 =====
 +
 +<code java>
 +System.getProperties().put("proxySet", "true");
 +System.getProperties().put("proxyHost", "172.31.170.14");
 +System.getProperties().put("proxyPort", "8080");
 +</code>
 +如果上面的不行,用下面这段:
 +<code java>
 +System.getProperties().setProperty("http.proxyHost", Const.proxyHost);
 +System.getProperties().setProperty("http.proxyPort", ""+Const.proxyPort);
 +</code>
 +
 +===== https代理设置 =====
 +
 +当然还可以设置https代理,如果证书有添加进去(Java\jdk1.6.0_14\jre\lib\security),需要指定证书
 +
 +<code java>
 + System.getProperties().setProperty("https.proxyHost", "10.85.40.153");
 + System.getProperties().setProperty("https.proxyPort", "8000");
 + System.setProperty("javax.net.ssl.trustStore", "ssl/ca.crt");
 +</code>