0

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?!

  • As of March 15th requests need to be updated to Oauth 1.0. See... http://stackoverflow.com/questions/36186538/making-yahoo-weather-api-request-with-oauth-1 – user6145628 Apr 01 '16 at 15:09

1 Answers1

0

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

blackxel
  • 196
  • 1
  • 8