string strUrl = "http://tw.yahoo.com/";
string strHtml = string.Empty;

WebRequest request = WebRequest.Create(strUrl);
WebResponse response = request.GetResponse();

HttpWebResponse httpWebResponse = (HttpWebResponse)response;
//這裡取得所使用的編碼
string charSet = httpWebResponse.CharacterSet;
Encoding code = Encoding.GetEncoding(charSet);

StreamReader sr = new StreamReader(response.GetResponseStream(), code);
strHtml = sr.ReadToEnd();

只是單純代碼而已。

文章標籤
全站熱搜
創作者介紹
創作者 souts 的頭像
souts

記憶所及之處

souts 發表在 痞客邦 留言(1) 人氣(261)