[英]Yahoo weather API gives no response
我正在嘗試編寫一個從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();
}
}
有任何想法嗎?!
只需更換
String url = "http://weather.yahooapis.com/forecastrss?p=USCA1116";
用
String url = "http://xml.weather.yahoo.com/forecastrss?p=USCA1116";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.