问题解决了!原来网页进行了Gzip压缩,解码就好了!
下面这段代码取到的数据怎么都是乱码呢?在同一网站的另一页面(https://www.),读取的数据又是正常的!请各位大哥大姐帮忙看看!程序代码:
string html = ""; string txtUri = "https://www."; HttpWebRequest req = WebRequest.Create(txtUri) as HttpWebRequest; HttpWebResponse res = req.GetResponse() as HttpWebResponse; Stream s = res.GetResponseStream(); if (res.StatusCode == HttpStatusCode.OK) { using (s) //using表示回收使用的内存 { using (StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"))) //UTF-8 Unicode defaule这些全都试过了 { html = sr.ReadToEnd(); sr.Close(); } s.Close(); } }
[ 本帖最后由 tig2 于 2013-12-10 13:15 编辑 ]