中国天气网接口地址:”http://wthrcdn.etouch.cn/WeatherApi?citykey=” + weatherCityCode(为城市code);
获取的信息为xml数据,所以在使用前我们可以将它转化成字符串,之后在序列化成天气类;
下面是转化过程中我们需要用到的方法(序列化的实体类在文章结尾附)
string weatherInfoUrl = "http://wthrcdn.etouch.cn/WeatherApi?citykey=" + weatherCityCode;
string weatherstr = getHtml2(weatherInfoUrl);
resp tempInfo = XmlDeSeralizer<resp>(weatherstr);
————转化过程中需要用到的方法—————–
private static string getHtml2(string url)
{
StringBuilder s = new StringBuilder(102400);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
HttpWebResponse response = (HttpWebResponse)wr.GetResponse(); head(response);
GZipStream g = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
byte[] d = new byte[