对WebClient扩展自动解压缩页面

WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题。

    public class MyWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri url)
        {
            HttpWebRequest request = base.GetWebRequest(url) as HttpWebRequest;
            request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            return request;
        }
    }

 

posted on 2013-12-29 10:16  一江春水  阅读(520)  评论(0编辑  收藏  举报

导航