java代理使用
- 2014-04-28 09:24:00
- 1147533288 原创
- 1225
场景:本地运行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下,需要的时候用的到。
文章分类
联系我
| 联系人: | meepo |
|---|---|
| 电话: | ***** |
| Email: | 1147533288@qq.com |
| QQ: | 1147533288 |