【发布时间】:2013-03-19 16:52:18
【问题描述】:
我想在 Tor 中使用 HtmlUnit。但是我无法使用 HtmlUnit 连接到 Tor(我正在运行 Tor Browser Bundle)。我在 TOR 文档中读到,我可以通过 localhost:9050 上的 socks 代理将 Tor 与其他应用程序一起使用。
我可以使用以下代码连接到在 google 上找到的普通代理:
WebClient webClient = new WebClient();
ProxyConfig prc = new ProxyConfig("xxx.xxx.xxx.xxx", 8081, false);
webClient.getOptions().setProxyConfig(prc);
HtmlPage page = webClient.getPage("http://whatismyipaddress.com");
System.out.print(page.asText());
但是如果我用 localhost 和 9050 替换 ip 和端口,那么它就不起作用了:
WebClient webClient = new WebClient();
ProxyConfig prc = new ProxyConfig("localhost", 9050, true);
webClient.getOptions().setProxyConfig(prc);
HtmlPage page = webClient.getPage("http://whatismyipaddress.com");
System.out.print(page.asText());
【问题讨论】:
-
可能不支持 SOCKS ?
-
@Peter:ProxyConfig 构造函数的最后一个参数是“isSocks”,所以我认为它支持 SOCKS。
-
您是否收到任何消息或只是超时?
-
@Peter:我收到以下错误:连接到目标主机时捕获 I/O 异常 (java.net.SocketException):连接被拒绝:连接
-
似乎 localhost 没有在端口 9050 上侦听或您的防火墙避免连接。