简体   繁体   中英

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.

Eclipse中代理设置的屏幕截图

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM