gpt4 book ai didi

c# - Gzip压缩asp.net c#

转载 作者:行者123 更新时间:2023-11-30 14:00:29 25 4
gpt4 key购买 nike

我只是想调整我的方法,以便在浏览器接受 gzip 时传输压缩数据。 else 部分已经可以工作了。我只想调整 if 部分。继承人的代码:

private void writeBytes()
{
var response = this.context.Response;

if (canGzip)
{
response.AppendHeader("Content-Encoding", "gzip");
//COMPRESS WITH GZipStream
}
else
{
response.AppendHeader("Content-Length", this.responseBytes.Length.ToString());
response.ContentType = this.isScript ? "text/javascript" : "text/css";
response.AppendHeader("Content-Encoding", "utf-8");
response.ContentEncoding = Encoding.Unicode;
response.OutputStream.Write(this.responseBytes, 0, this.responseBytes.Length);
response.Flush();
}
}

最佳答案

看起来你想添加 Response.Filter,见下文。

private void writeBytes()
{
var response = this.context.Response;
bool canGzip = true;

if (canGzip)
{
Response.Filter = new System.IO.Compression.GZipStream(Response.Filter, System.IO.Compression.CompressionMode.Compress);
Response.AppendHeader("Content-Encoding", "gzip");
}
else
{
response.AppendHeader("Content-Encoding", "utf-8");
}

response.AppendHeader("Content-Length", this.responseBytes.Length.ToString());
response.ContentType = this.isScript ? "text/javascript" : "text/css";
response.ContentEncoding = Encoding.Unicode;
response.OutputStream.Write(this.responseBytes, 0, this.responseBytes.Length);
response.Flush();
}

}

关于c# - Gzip压缩asp.net c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10639337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com