发送一个请求以后,不是能得到一个服务器的响应么,服务器的响应里面就有编码格式的,比如
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(@urlstr);
myWebRequest.Timeout = 10000;
myWebRequest.Method = "GET";
HttpWebResponse res = (HttpWebResponse)myWebRequest.GetResponse();
res.ContentType//这个里面一般就有编码格式了,或者res.CharacterSet。
private string GetWebresourceFile(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.UTF8);
string SourceCode = sr.ReadToEnd();
resStream.Close();
sr.Close();
return SourceCode;
}