核心代码如下:
public class HttpClientUtil {
<span style="white-space:pre"> </span>
private static String proxyHost="192.168.1.194";
private static int proxyPort=10890;
private static String proxyName="test";
private static String proxyPwd="123321";
public static String getWithProxy(String url, Map<String, String> headers, String charset) {
//用户名和密码验证
<strong>Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
PasswordAuthentication p=new PasswordAuthentication(proxyName, proxyPwd.toCharArray());
return p;
}
});</strong>
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory> create()