对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;

        }

    }

 

你可能感兴趣的:(client)