HttpWebResponse 四种accept-encoding解析(gzip, deflate, br,identity)

HttpWebResponse 四种accept-encoding解析(gzip, deflate, br,identity[默认])

            var hwrs = (HttpWebResponse)hwr.GetResponse()
            if (hwrs.ContentEncoding.ToLower().Contains("gzip"))
            {
     
                outhtml = new StreamReader(new GZipStream(hwrs.GetResponseStream(), CompressionMode.Decompress)).ReadToEnd();
            }
            else if (hwrs.ContentEncoding.ToLower().Contains("deflate"))
            {
     
                outhtml = new StreamReader(new DeflateStream(hwrs.GetResponseStream(), CompressionMode.Decompress)).ReadToEnd();
            }
            else if (hwrs.ContentEncoding.ToLower().Contains("br"))
            {
     
                //需要从NuGet引用 Brotli.Net
                outhtml = new StreamReader(new Brotli.BrotliStream(hwrs.GetResponseStream(), CompressionMode.Decompress)).ReadToEnd();
            }
            else
            {
     
                outhtml = new StreamReader(hwrs.GetResponseStream()).ReadToEnd();
            }

你可能感兴趣的:(HttpWebResponse 四种accept-encoding解析(gzip, deflate, br,identity))