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();
}

————————————————
版权声明:本文为CSDN博主「wpyok168」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wpyok168/article/details/105537083

posted @ 2022-11-20 19:50  LoveCoder  阅读(306)  评论(0编辑  收藏  举报