java 使用htmlunit框架,设置代理,连接网页出现connection refused异常

做爬虫项目需要用到代理,问题代码如下

  ProxyConfig proxyConfig = webClient.getOptions().getProxyConfig();
            proxyConfig.setProxyHost(ipPort.getIp());
            proxyConfig.setProxyPort(ipPort.getPort());
            HtmlPage page = webClient.getPage(ipTestWeb);

其中ip和port的值都死存在的,在client获取页面时报错
rg.apache.http.conn.HttpHostConnectException: Connect to 58.61.185.70:9797 [/58.61.185.70] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:183)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1351)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1268)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:381)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:303)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:435)
at cn.com.test.proxy.TestIP.parseIP(TestIP.java:67)
at cn.com.test.proxy.TestIP.getRandomUsefulProxy(TestIP.java:140)
at cn.com.test.proxy.TestIP.main(TestIP.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问