(1)原始方案
System.Text.Encoding.Default
採用當前的默認編碼,可以解決大部分問題,但是很多跟情況下同樣會出錯。
(2)HTTPWebrequest 的CharacterSet(MSND上給的方案,本來應該的做法)
該屬性可以返回該網站編碼,但是總爲空。
(3)老外的解決之道
Sven Groot
I came across a very silly (and annoying) bug in the HttpWebResponse.CharacterSet property. Let's see if you can spot it (code extracted with reflector):
(4)另一種方法(先獲取內容,再根據內容來判)
(5)結合3/4的辦法(當然去看HttpWebResponse函數的源代碼了)
//得到CharacterSet