ServiceStack - How To Compress Requests From Client

眉间皱痕 提交于 2019-12-11 10:06:35

问题


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.

Thanks!


回答1:


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;

If the Web Server returns a compressed response indicated with the Content-Encoding HTTP Response header the Service Client transparently decompresses it.

Support for client Gzip + Deflate compression has also been added to ServiceStack Server and all C# Service Clients in this commit.

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 { ... });

This feature is available from v4.5.5+ that's now available on MyGet.



来源:https://stackoverflow.com/questions/34211036/servicestack-how-to-compress-requests-from-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!