如何配置httpClient到jsoup

时间:2016-08-09 10:37:50

标签: java jsoup httpclient

我正在尝试将http客户端设置为Jsoup以使用TOR作为代理,但是我无法找到将客户端设置为Jsoup的方法,我想知道如何知道Jsoup没有#&# 39;需要httpClient配置吗?

1 个答案:

答案 0 :(得分:1)

Jsoup没有使用HttpClient,但您可以使用以下方式设置代理:

// Setup proxy
Proxy proxy = new Proxy(Proxy.Type.HTTP,
        InetSocketAddress.createUnresolved("127.0.0.1", 80));

// Setup the authenticator
Authenticator authenticator = new Authenticator() {

    public PasswordAuthentication getPasswordAuthentication() {
        return (new PasswordAuthentication("user",
                "password".toCharArray()));
    }
};
Authenticator.setDefault(authenticator);

// Send a request using the proxy
Document doc = Jsoup.connect("http://www.example.com/")
        .proxy(proxy)
        .get();