RestSharp compress request while making rest call to server

假如想象 提交于 2019-12-01 00:42:32

RestSharp supports HTTP compression since version 102.7. I'm not sure if this works only for Windows Phone or compression is supported for all platforms.

The most common algorithms are GZip and Deflate, although the actual level of compression is usually controlled by the server.

UPDATE:

I just verified using Fiddler that HTTP Compression is enabled by default in 103.1. The following code returns a page encoded using GZip:

        var target = "http://msdn.microsoft.com/";
        var client=new RestClient(target);
        var request = new RestRequest("",Method.GET);
        var response = client.Execute(request);
        Console.WriteLine(response.Content);

There is no need to add the Accept-Encoding header.

Compression will only work if the server supports it. Otherwise the response will be uncompressed.

This means that the Java service will have to enable HTTP compression as well.

If the response is compressed the Content-Encoding header will be set to the compression method, eg. gzip.

To check this visually, open Fiddler and check the responce to the RestRequest. The Transformer tab of the Response pane displays the compression settings.

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