问题描述
有没有人提供有关如何在客户端上设置ServiceStack以便使用GZip自动压缩所有请求的示例?我已经找到了很好的示例,说明了如何使用Module在服务器端自动解压缩请求,而对于客户端则什么也没有。
Does anyone have any examples of how to setup ServiceStack on the client side to automatically compress all requests using GZip? I've found good examples of how to automatically decompress requests on the server side using a Module but nothing for the client side.
谢谢!
推荐答案
ServiceStack的自动发送 Accept-Encoding:gzip,deflate
HTTP标头,指示其接受GZip或Deflated响应。可以通过以下方式禁用它:
ServiceStack's Service Clients automatically sends the Accept-Encoding: gzip,deflate
HTTP Header indicating it accepts a GZip or Deflated response. It can be disabled with:
client.DisableAutoCompression = true;
如果Web服务器返回由 Content-Encoding
HTTP响应标头,服务客户端透明地对其进行解压缩。
If the Web Server returns a compressed response indicated with the Content-Encoding
HTTP Response header the Service Client transparently decompresses it.
对客户端Gzip + Deflate压缩的支持也已添加到ServiceStack Server和所有C#服务客户端中在中。
Support for client Gzip + Deflate compression has also been added to ServiceStack Server and all C# Service Clients in this commit.
这使您可以使用新的 RequestCompressionType
属性发送客户端请求,例如:
This lets you send client requests with the new RequestCompressionType
property, e.g:
var client = new JsonServiceClient(baseUrl)
{
RequestCompressionType = CompressionTypes.GZip,
};
var response = client.Post(new NameOfDto { ... });
此功能可从v4.5.5 +版本开始使用,该版本现在为。
This feature is available from v4.5.5+ that's now available on MyGet.
这篇关于ServiceStack-如何压缩来自客户端的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!