简体   繁体   中英

Yahoo weather API gives no response

I am trying to write a java client that get the weather from yahoo weather API.

I get this exception every time: Server returned HTTP response code: 401 for URL: http://weather.yahooapis.com/forecastrss?p=USCA1116

the code:

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();

    }

}

any ideas?!

Just replace

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

With

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM