问题
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