12

java代理使用

2014-04-28 09:24:00    1147533288    1224    原创
摘要:java,代理

刚从同事那里要来的,未验证。

场景:本地运行java执行定时发送短信,因公司代理无法正常连接网络,代码中设置代理相关配置即可。代码如下:

[code jang="java"]
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", PROXYHOST);
System.getProperties().put("proxyPort", PROXYPORT);
if ( StringUtils.isEmpty(PROXYUSER) && StringUtils.isEmpty(PROXYPWD) ){
Authenticator.setDefault(
  new Authenticator() {
 public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
PROXYUSER, PROXYPWD.toCharArray());
 }
  }
);
System.getProperties().put("http.proxyUser", PROXYUSER);
System.getProperties().put("http.proxyPassword", PROXYPWD);
}
[/code]

mark下,需要的时候用的到。
苏ICP备18038013号-1
蝉知 蝉知5.2