webclinet downstring 搜狐 为什么是个?号

c#  搜狐 腾讯 都是这样。。。新浪可以

我试了一下,继检查,是搜狐的内容经过了GZIP压缩,报以才出现你这样的问题。具体解决方法如下:

System.Net.WebClient wc = new System.Net.WebClient();
wc.BaseAddress = "http://www.sohu.com";

//注意,new GZipStream。。。这一句是解决问题的重点,需要引用命名空间 System.IO.Compression;

using (System.IO.Stream objStream = new GZipStream(wc.OpenRead("/"), CompressionMode.Decompress))
        {

            using (System.IO.StreamReader _read = new System.IO.StreamReader(objStream, System.Text.Encoding.Default))
            {
                Response.Write(_read.ReadToEnd());
            }
           
        }




OK,问题成功解决

posted @ 2012-05-05 09:11  郑文亮  阅读(488)  评论(0编辑  收藏  举报