I am trying to set http client to Jsoup to use TOR as proxy, but I can't find a way to set client to Jsoup, I'm wondering how can I do that knowing that Jsoup doesn't need an httpClient configuration?
Asked
Active
Viewed 1,141 times
0
-
Possible duplicate of [How to add proxy support to Jsoup (HTML parser)?](http://stackoverflow.com/questions/7482748/how-to-add-proxy-support-to-jsoup-html-parser) – Zack Aug 09 '16 at 13:45
1 Answers
2
Jsoup doesn't use HttpClient, but you can set the proxy using:
// 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();

Davide Pastore
- 8,678
- 10
- 39
- 53
-
Thank you for your response, for the proxy i am using a username and password, does the createUnresolved supports more parameters ? – user3900368 Aug 11 '16 at 09:19