我正在使用openStream with Java
in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
该方法等待来自发出URL的服务的响应多长时间?
我正在成为同样的错误消息,我不知道为什么。
java.net.UnknownHostException: dev.virtualearth.net
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.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.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
由于
答案 0 :(得分:1)
openStream()
方法是URL.openConnection().getInputStream()
您可以自己设置超时:
URLConnection con = url.openConnection();
con.setConnectTimeout(XXX);
来自JDK: “如果在建立连接之前超时到期,则会引发 java.net.SocketTimeoutException。超时为零被解释为无限超时。”
默认超时为0
您的异常“抛出表示无法确定主机的IP地址。”
答案 1 :(得分:1)
您似乎可能在防火墙后面,因此您可以添加:
System.setProperty(“java.net.useSystemProxies”,“true”); //如果你设置了系统代理
或
System.setProperty( “http.proxySet”, “真”);
System.setProperty( “proxyPort”, “端口”);
System.setProperty( “ProxyHost的”, “的ProxyHost”);
System.setProperty(“http.proxyUser”,“user”);
System.setProperty(“http.proxyPassword”,“password”);
到相关的java类
答案 2 :(得分:0)
java.net.UnknownHostException: dev.virtualearth.net
表示您的DNS配置不正确,因为Java不知道如何将dev.virtualearth.net解析为IP地址。您要打开的URL的字符串表示形式是什么?