富贵资源网 Design By www.hznty.com
本文实例讲述了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" + 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程序设计有所帮助。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...