1,通过分析Header提取编码。
WebRequest webRequest = WebRequest.Create(url); HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); Regex reg_charset = new Regex(@"charset\b\s*=\s*(?<charset>[^""]*)") ; WebHeaderCollection headers = webResponse.Headers; string encodingName = string.Empty; string contentType = headers["Content-Type"]; if (contentType.IndexOf("charset") > 0 && reg_charset.IsMatch(ContentType)) { encodingName = reg_charset.Match(contentType).Groups["charset"].Value; }
引用地址 http://blog.useasp.net/default.aspx