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.