0

I'm trying to get Jsoup to connect to reddit and get its title via a proxy server using this code:

package js;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Test {
    public static void main(String[] args) throws Exception {
        System.setProperty("http.proxyHost", "123.456.789.2342.");
        System.setProperty("http.proxyPort", "5846123232");

        Document doc = Jsoup.connect("http://reddit.com/").get();
        String title = doc.title();
        System.out.println(title);
    }
}

Despite the proxy data obviously being wrong, this code still works and prints

reddit: the front page of the internet

so it didn't seem to use or try to use that proxy server at all. How do I get Jsoup to use a given proxy server?

parsecer
  • 4,758
  • 13
  • 71
  • 140
  • does [this post](https://stackoverflow.com/questions/7482748/how-to-add-proxy-support-to-jsoup) address your question? – Kaan Jan 08 '20 at 22:43
  • No. One of the top solutions: https://stackoverflow.com/a/11878268/4759176 is exactly what I've used and my question is basically about why it doesn't work – parsecer Jan 08 '20 at 22:44
  • I ran your code and got this: `Exception in thread "main" java.net.UnknownHostException: 123.456.789.2342` – Kaan Jan 08 '20 at 22:50
  • @kaan So it could be an IDE issue maybe? I'm using Idea Intellij – parsecer Jan 09 '20 at 00:39
  • I also ran your code in IntelliJ. I don't know what the issue is, but it appears your code itself is ok. – Kaan Jan 09 '20 at 16:52
  • @kaan You got the same error when running inside Idea Intellij? I ended up using `Document doc = Jsoup.connect("http://reddit.com/").proxy(proxy).timeout(6000).get();` which does make use of proxy and produces an error when one is wrong. – parsecer Jan 09 '20 at 17:22

0 Answers0