首页 > 其他分享 >HttpWebResponse 四种accept-encoding解析(gzip, deflate, br,identity【转】

HttpWebResponse 四种accept-encoding解析(gzip, deflate, br,identity【转】

时间:2022-11-20 20:02:10浏览次数:51  
标签:encoding HttpWebResponse hwrs outhtml GetResponseStream new StreamReader identit

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

标签:encoding,HttpWebResponse,hwrs,outhtml,GetResponseStream,new,StreamReader,identit
From: https://www.cnblogs.com/Jerseyblog/p/16909340.html

相关文章