Yahoo weather API没有回复

时间:2016-03-27 17:35:05

标签: java url yahoo

我正在尝试编写一个从yahoo weather API获取天气的Java客户端。

我每次都得到这个例外: 服务器返回HTTP响应代码:401为URL:http://weather.yahooapis.com/forecastrss?p=USCA1116

代码:

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        //  log.info( "Retrieving Weather Data" );
        String zipcode="USCA1116";
            String url = "http://weather.yahooapis.com/forecastrss?p=USCA1116";
            URLConnection connection = new URL(url).openConnection();

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    connection.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();

    }

}

任何想法?!

1 个答案:

答案 0 :(得分:0)

只需替换

    String url = "http://weather.yahooapis.com/forecastrss?p=USCA1116";

使用

    String url = "http://xml.weather.yahoo.com/forecastrss?p=USCA1116";

https://forum.rainmeter.net/viewtopic.php?f=13&t=23010