The UnKnownHostExceptionJsoup execution execute () error caused by the proxy Setting Problem

Source: Internet
Author: User
When the following statement is executed, an UnKnownHostException exception is thrown: Unknown cute (); [09-

An UnKnownHostException exception is thrown when the following statement is executed: Response response = Jsoup. connect (path ). userAgent ("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.20.2.0 Safari/535.21 "). timeout (10000 ). execute (); [09-

An UnKnownHostException is thrown when the following statement is executed:

Response response = Jsoup.connect(path)                .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")                .timeout(10000)                .execute();

[09-09 08:26:13.822] java.net.UnknownHostException: www.baidu.com[09-09 08:26:13.823] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)[09-09 08:26:13.823] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

If you use a proxy to access the Internet, it should be related to the proxy settings. You need to set the proxy in the operating system or program. (Assume that the proxy server is 192.168.10.20: 8080)

To request a url, set the system's network proxy directly. In Windows, set the proxy in the Internet option:

In Linux, the settings are as follows:

Set the environment variables in the/etc/profile file to specify the proxy server addresses used by the HTTP, HTTPS, and FTP protocols respectively:

Http_proxy = 192.168.10.20: 8080https_proxy = 192.168.10.20: 8080ftp_proxy = 192.168.10.20: 8080no_proxy = 192.168.10. # Do not use the proxy export http_proxy https_proxy no_proxy when accessing the LAN address (192.168.10.0/24)

Save the configuration and exit. log out and log on again to take effect.

Set proxy in Java program:

If UnKnownHostException still occurs after this configuration, it is likely that the agent configured by the system does not take effect. You can add the following proxy in the program:

System.getProperties().put("http.proxySet", "true");System.getProperties().put("http.proxyHost", "192.168.10.20");System.getProperties().put("http.proxyPort", "8080");// System.getProperties().put("http.proxyUser", user);// System.getProperties().put("http.proxyPassword", password);System.getProperties().put("http.nonProxyHosts", "localhost|127.0.0.1");

Original article address: The UnKnownHostException Jsoup execution execute () error caused by proxy settings. Thank you for sharing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.