http://wthrcdn.etouch.cn/WeatherApi?city=%E5%8C%97%E4%BA%AC 可以查询北京的天气。city=后面是城市的名字,此处为北京。
获取XML数据的C#代码
WebRequest request = WebRequest.Create("http://wthrcdn.etouch.cn/WeatherApi?city=%E5%8C%97%E4%BA%AC");WebResponse response = request.GetResponse();GZipStream GStream = new GZipStream(response.GetResponseStream(), ComPRessionMode.Decompress, true);StreamReader reader = new StreamReader(GStream, Encoding.UTF8);string str = reader.ReadToEnd();reader.Close();response.Close();str即为获取的XML格式天气信息。通过后续XML解析获取数据。
这个天气api给的信息比较详细。附一张测试程序截图。
代码通过Visual Studio 2015测试。
新闻热点
疑难解答