我尝试在Eclipse中添加proxy,nonProxyHost等但无法通过此错误。我还阅读了java.net.UnknownHostException
周围的很多页面,但没有运气。以下是片段和例外。
URL url = new URL("https://xyz.com/Something");
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection)connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
OutputStream out = httpConn.getOutputStream(); //Fails with
//Exception in thread "main" java.net.UnknownHostException: xyz.com
完整堆栈跟踪:
Exception in thread "main" java.net.UnknownHostException: xyz.com
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
我尝试通过代码在代理下面设置:
System.setProperty("useDefaultWebProxy", "true");
System.setProperty("https.proxyHost", "my_proxy_server");
System.setProperty("https.proxyPort", "8080");
System.setProperty("https.nonProxyHosts", "xyz.com");
此外,在Eclipse中,我在Window -> Preferences -> General -> Network Connection