2016-03-27 141 views
0

我想寫一個java客戶端,從雅虎天氣API獲取天氣。 服務器返回的HTTP響應代碼:雅虎天氣API沒有迴應

每次我得到這個例外401網址: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(); 

    } 

} 

任何想法?

+0

由於3月15日的請求需要更新到OAuth 1.0。參見... http://stackoverflow.com/questions/36186538/making-yahoo-weather-api-request-with-oauth-1 – user6145628

回答