The Yahoo Weather API changed URL this week and my app fails to connect now. Please see below the code with the new URL and below in comment the old 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"; }
}
I get the following error:
Exception: Exception thrown: 'System.Net.WebException' in System.dll ("The remote server returned an error: (400) Bad Request."). Exception thrown: 'System.Net.WebException' in System.dll ("The remote server returned an error: (400) Bad Request.") 12.32s [11632]