asp.net实现根据城市获取天气预报的方法
作者:happy664618843
这篇文章主要介绍了asp.net实现根据城市获取天气预报的方法,涉及asp.net调用新浪接口获取天气预报信息的实现技巧,非常简单实用,需要的朋友可以参考下
本文实例讲述了asp.net实现根据城市获取天气预报的方法。分享给大家供大家参考,具体如下:
public void GetWetheaerByCity(string cityName) { string city = cityName; string mycity = HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("GB2312")); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.sina.com/index.php?city=" + cityName); //HttpWebRequest 对象 获取GetResponse 转换成HttpWebResponse System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse; //通过HttpWebResponse response.GetResponseStream()获取输出流 Stream str = response.GetResponseStream(); StreamReader reader = new StreamReader(str, System.Text.Encoding.GetEncoding("GB2312")); string weathhtml = reader.ReadToEnd(); str.Close(); reader.Close(); }
希望本文所述对大家asp.net程序设计有所帮助。