我试图在代理后面使用HtmlUnit:
public class App {
public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "172.23.232.10");
System.setProperty("http.proxyPort", "8080");
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://www.google.com");
System.out.println(page.getTitleText());
}
}
我有一个连接超时异常
Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connect to www.google.com:80 [www.google.com/172.217.16.196] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
是否有指定HtmlUnit(浏览器)的代理属性的解决方案
答案 0 :(得分:2)
试试这个:
ProxyConfig proxyConfig = new ProxyConfig("172.23.232.10", 8080);
webClient.getOptions().setProxyConfig(proxyConfig);
您有更多信息here。
答案 1 :(得分:1)
你可以这样做proxy
:
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45, proxyHost, proxyPort);