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();
只是單純代碼而已。
全站熱搜