2014/12/16

Question:
最近使用WebClient.DownloadString後,
收到的字串如果遇到中文字會出現亂碼。

Solve:
WebClient wc = new WebClient();
byte[] htmlByte = wc.DownloadData("你的網站");
string htmlText = Encoding.UTF8.GetBytes(htmlByte);

因為將網頁直接換成字串會有編碼問題,
那就先利用WebClient.DownloadData將網頁下載成位元組,
再利用Encoding.UTF8.GetBytes來轉成字串,
這樣中文字顯示也不會有問題囉!

參考資料:http://www.dotblogs.com.tw/lastresort/archive/2012/03/21/70915.aspx


16 Dec 2014

0 意見:

張貼留言

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.