我正在尝试在代理后面使用 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

关于java - 在代理后面使用 HtmlUnit,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36398670/

10-12 14:24