欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# webclient中文亂碼問題解決方法

 更新時(shí)間:2016年05月23日 11:27:50   作者:秦風(fēng)  
本文介紹使用webclient抓取遠(yuǎn)程頁(yè)面出現(xiàn)亂碼的處理方法,希望對(duì)大家有所幫助。

webclient在調(diào)用DownloadData或者DownloadString的時(shí)候請(qǐng)求回來(lái)的數(shù)據(jù)出現(xiàn)亂碼問題,解決辦法如下:

1、設(shè)置webclient的編碼格式為目標(biāo)編碼格式

復(fù)制代碼 代碼如下:
WebClient web = new WebClient();//創(chuàng)建webclient對(duì)象
web.Encoding = System.Text.Encoding.UTF8;//定義對(duì)象語(yǔ)言
string returns = web.DownloadString("_http://www.weather.com.cn/data/sk/101310101.html");//向一個(gè)連接請(qǐng)求資源

2、先獲取數(shù)據(jù),然后轉(zhuǎn)碼

復(fù)制代碼 代碼如下:
WebClient wc = new WebClient();
Byte[] pageData = wc.DownloadData(" string rr = Encoding.GetEncoding("utf-8").GetString(pageData);

總結(jié)下來(lái),還是編碼的問題,不論哪種方法,設(shè)置好編碼即可。

相關(guān)文章

最新評(píng)論