使用代理ip,端口訪問目標網址。
RequestConfig config = null;
//使用代理
if(null != proxy && StringUtils.isNotBlank(proxy.ip) && proxy.port > 0){
HttpHost proxy = new HttpHost(proxy.ip, proxy.port);
config = RequestConfig.custom().setProxy(proxy).build();
}else{
//沒有代理,使用默認值
config = RequestConfig.custom().build();
}
HttpGet hg = new HttpGet(url);
//設置代理
hg.setConfig(config);
