0

我尝试运行以下示例:

http://www.sonatype.com/books/mvnex-book/reference/customizing-sect-custom-exec.html

失败的代码基本上是:

String url = "http://weather.yahooapis.com/forecastrss?p=60202";
URLConnection conn = new URL(url).openConnection();
return conn.getInputStream();

我可以完美地从浏览器/提要阅读器访问 URL。但是,在 Java 中运行代码时,我得到一个

Exception in thread "main" java.net.UnknownHostException: weather.yahooapis.com

任何想法,可能是什么问题?可能是我们办公室的代理阻止了 URL,但是我可以从浏览器访问它吗?

最好的,威尔

4

4 回答 4

1

自 2019 年 1 月 3 日起,该 URL 已停用。有关更多信息,请参阅此链接:

https://developer.yahoo.com/weather/

于 2019-02-10T03:26:13.100 回答
0

该网站对我来说很好阅读......我假设这意味着你被那个代理阻止了。尝试System.setProperty("http.agent", "Fake Agent");欺骗代理/站点认为您不是 Java(通常 http.agent 是 Java/版本)

于 2012-08-24T15:39:36.937 回答
0

您是否已阻止 Java 虚拟机访问 Internet?您看到的异常意味着无法将主机解析为 IP。

请检查您的网络安全设置或防火墙以允许 JVM 连接到您请求的站点。

于 2012-08-24T16:22:01.183 回答
0

您是否在 Android Manifest 中授予了 Internet 权限?

于 2013-07-18T23:48:59.417 回答