Web Api gzip 压缩

Web Api gzip compression

我已经将此 URL 用于 Web API 压缩,但是当我看到 fiddler 中的输出 header 不是 zip。有多个 Zip 选项可用,例如 GZIP、BZIP2 DEFLATE 不确定使用哪一个,请在此处提供帮助

我尝试了以下解决方案,但它们都不起作用:

http://benfoster.io/blog/aspnet-web-api-compression

there are multiple Zip option are available example GZIP, BZIP2 DEFLATE not sure which one to use kindly help here

这个列表将被发送到服务器并让它知道客户端关于压缩的首选项。意思是"I first prefer GZIP. If GZIP not supported by the server side then fallback to BZIP2 DEFLATE compression. If BZIP2 DEFLATE not supported then the server will not do any compression."

有人已经创建了一个 nuget 包,该包使用了您刚刚提出问题的实现。软件包名称是 Microsoft.AspNet.WebApi.MessageHandlers.Compression 安装以下两个软件包:

  • Microsoft.AspNet.WebApi.Extensions.Compression.Server
  • System.Net.Http.Extensions.Compression.Client

如果您不需要客户端库,那么只需要 Web API 项目中的服务器端包。

要使用它,您需要修改以在 Gloabl.asax.cs 中的 Application_Start 方法末尾添加以下行:

GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));

要了解有关此软件包的更多信息,请查看此 link