编程语言
首页 > 编程语言> > java-在代理后面使用HtmlUnit

java-在代理后面使用HtmlUnit

作者:互联网

我试图在代理后面使用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(浏览器)的代理属性

解决方法:

尝试这个:

ProxyConfig proxyConfig = new ProxyConfig("172.23.232.10", 8080);
webClient.getOptions().setProxyConfig(proxyConfig);

您有更多信息here.

标签:proxy,htmlunit,java
来源: https://codeday.me/bug/20191118/2031302.html