Yahoo Weather API изменил URL-адрес на этой неделе, и теперь мое приложение не может подключиться. См. ниже код с новым URL-адресом и ниже в комментарии со старым URL-адресом.
private void GetWeather()
{
try
{
string query = String.Format("https://query.yahooapis.com/v1/public/yql?q=" + Settings.Default.WOEID.ToString() + "&u=" + Settings.Default.Temperature);
//string query = String.Format("https://weather.yahooapis.com/forecastrss?w=" + Settings.Default.WOEID.ToString() + "&u=" + Settings.Default.Temperature);
XmlDocument wData = new XmlDocument();
wData.Load(query);
XmlNamespaceManager man = new XmlNamespaceManager(wData.NameTable);
man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNodeList nodes = wData.SelectNodes("/query/results/channel/item/yweather:forecast", man);
//XmlNodeList nodes = wData.SelectNodes("/rss/channel/item/yweather:forecast", man);
Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", man).Attributes["temp"].Value;
Condition = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", man).Attributes["text"].Value;
Humidity = channel.SelectSingleNode("yweather:atmosphere", man).Attributes["humidity"].Value;
WinSpeed = channel.SelectSingleNode("yweather:wind", man).Attributes["speed"].Value;
Town = channel.SelectSingleNode("yweather:location", man).Attributes["city"].Value;
TFCond = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", man).Attributes["text"].Value;
TFHigh = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", man).Attributes["high"].Value;
TFLow = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", man).Attributes["low"].Value;
QEvent = "connected";
}
catch { QEvent = "failed"; }
}
Я получаю следующую ошибку:
Исключение: Возникло исключение: «System.Net.WebException» в System.dll («Удаленный сервер вернул ошибку: (400) неверный запрос».). Возникло исключение: «System.Net.WebException» в System.dll («Удаленный сервер вернул ошибку: (400) неверный запрос».) 12,32 с [11632]