asp.net实现根据城市获取天气预报的方法
本文实例讲述了asp.net实现根据城市获取天气预报的方法。分享给大家供大家参考,具体如下:
publicvoidGetWetheaerByCity(stringcityName){ stringcity=cityName; stringmycity=HttpUtility.UrlEncode(city,System.Text.Encoding.GetEncoding("GB2312")); System.Net.HttpWebRequestrequest=(System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.sina.com/index.php?city="+cityName); //HttpWebRequest对象获取GetResponse转换成HttpWebResponse System.Net.HttpWebResponseresponse=request.GetResponse()asSystem.Net.HttpWebResponse; //通过HttpWebResponseresponse.GetResponseStream()获取输出流 Streamstr=response.GetResponseStream(); StreamReaderreader=newStreamReader(str,System.Text.Encoding.GetEncoding("GB2312")); stringweathhtml=reader.ReadToEnd(); str.Close(); reader.Close(); }
希望本文所述对大家asp.net程序设计有所帮助。