本文實(shí)例講述了asp.net實(shí)現(xiàn)根據(jù)城市獲取天氣預(yù)報(bào)的方法。分享給大家供大家參考,具體如下:
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 轉(zhuǎn)換成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程序設(shè)計(jì)有所幫助。
標(biāo)簽:麗江 汕頭 宜春 婁底 本溪 河南 吉林 重慶
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net實(shí)現(xiàn)根據(jù)城市獲取天氣預(yù)報(bào)的方法》,本文關(guān)鍵詞 asp.net,實(shí)現(xiàn),根據(jù),城市,獲取,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。