Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup unable to connect

I have downloaded the Jsoup jar and added it in the library. I have added the proxy settings in Eclipse. But when ever I try this in the code:

Document doc = Jsoup.connect("http://www.wikipedia.com").get();
it throws the following error:
Errorjava.net.ConnectException: Connection refused: connect

Can anyone help me figure out a solution? Is there a specific way to set the proxy (in case I am missing something). Attaching screenshot of the same. Any help/guidance will be highly appreciated.

Screenshot of the proxy setting in Eclipse

like image 687
Tanny Avatar asked Jun 20 '14 09:06

Tanny


2 Answers

The proxy in Eclipse only sets it for connecting to update software, etc. It has nothing to do with the proxy used by your programs.

To set the proxy you can try:

System.setProperty("http.proxyHost", "proxy.xxx.com"); // or the IP
System.setProperty("http.proxyPort", "6050");
Document doc = Jsoup.connect("http://www.wikipedia.com").get();

Or simply set the System properties when executing your program:

-Dhttp.proxyHost=proxy.xxx.com -Dhttp.proxyPort=6050
like image 100
Jean Logeart Avatar answered Nov 05 '22 13:11

Jean Logeart


why dont you try this, if this works fine then there is problem with your steps to set proxy

URL u =new URL("www.google.com");
    URLConnection usn=u.openConnection();
    usn.connect();

there is also a another constructor which has proxy as a parameter

 URLConnection usn=u.openConnection(your proxy)
like image 34
swapnil gandhi Avatar answered Nov 05 '22 14:11

swapnil gandhi