Merge branch 'hepan-master'
commit
9de64ea0f2
|
@ -6,6 +6,7 @@ import org.apache.http.HttpHost;
|
||||||
|
|
||||||
import us.codecraft.webmagic.proxy.Proxy;
|
import us.codecraft.webmagic.proxy.Proxy;
|
||||||
import us.codecraft.webmagic.proxy.SimpleProxyPool;
|
import us.codecraft.webmagic.proxy.SimpleProxyPool;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import us.codecraft.webmagic.proxy.ProxyPool;
|
import us.codecraft.webmagic.proxy.ProxyPool;
|
||||||
import us.codecraft.webmagic.utils.UrlUtils;
|
import us.codecraft.webmagic.utils.UrlUtils;
|
||||||
|
|
||||||
|
@ -53,6 +54,8 @@ public class Site {
|
||||||
|
|
||||||
private HttpHost httpProxy;
|
private HttpHost httpProxy;
|
||||||
|
|
||||||
|
private UsernamePasswordCredentials usernamePasswordCredentials; //代理用户名密码设置
|
||||||
|
|
||||||
private ProxyPool httpProxyPool;
|
private ProxyPool httpProxyPool;
|
||||||
|
|
||||||
private boolean useGzip = true;
|
private boolean useGzip = true;
|
||||||
|
@ -486,6 +489,15 @@ public class Site {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UsernamePasswordCredentials getUsernamePasswordCredentials() {
|
||||||
|
return usernamePasswordCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Site setUsernamePasswordCredentials(UsernamePasswordCredentials usernamePasswordCredentials) {
|
||||||
|
this.usernamePasswordCredentials = usernamePasswordCredentials;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ProxyPool getHttpProxyPool() {
|
public ProxyPool getHttpProxyPool() {
|
||||||
return httpProxyPool;
|
return httpProxyPool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,15 @@ public class HttpClientGenerator {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(site!=null&&site.getHttpProxy()!=null&&site.getUsernamePasswordCredentials()!=null){
|
||||||
|
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||||
|
credsProvider.setCredentials(
|
||||||
|
new AuthScope(site.getHttpProxy()),//可以访问的范围
|
||||||
|
site.getUsernamePasswordCredentials());//用户名和密码
|
||||||
|
httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
|
||||||
|
}
|
||||||
|
|
||||||
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
|
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
|
||||||
httpClientBuilder.setDefaultSocketConfig(socketConfig);
|
httpClientBuilder.setDefaultSocketConfig(socketConfig);
|
||||||
if (site != null) {
|
if (site != null) {
|
||||||
|
|
Loading…
Reference in New Issue