如何通过袜子端口使用Jsoup
?我在documentation中找不到任何内容。
Jsoup changelog:
Release 1.9.1 [2016-Apr-16]
Added support for HTTP and SOCKS request proxies, specifiable per connection.
答案 0 :(得分:1)
JSoup的连接实际上基于java.net.HttpURLConnection
。这就是为什么系统代理首先对JSoup
有效的原因。
HttpURLConnection
的工作方式是使用ProxySelector
对象,该对象返回给定URI
的所有可能的代理。
这是工作代码:
Document doc = Jsoup //
.connect("http://www.example.com/") //
.proxy("127.0.0.1", 8080) // sets a HTTP proxy
.userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2") //
.header("Content-Language", "en-US") //
.get();
有关Jsoup代理的更多信息,请检查this link
答案 1 :(得分:0)
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("1.2.3.4", 8080));
Document doc = Jsoup.connect("url").proxy(proxy).get();