问题
I am consuming a rest api written in java in my C# client. I was pumping hell lot of data to server and I was using RestSharp.dll for the purpose of making rest calls. What I will do is construct an object and add that directly in body of RestSharp request object and mention .netserializer for it. So it will automatically serialize it and post it. All works great.
Now I need to apply LZO or GZIP compression. So that server will have less load.
I know how to implement both compression techniques. But how to implement it with RestSharp request object?
What I got to do. I am adding object to body of request. When to perform compression?
Anyhelp...
Thanks
回答1:
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.
来源:https://stackoverflow.com/questions/10914672/restsharp-compress-request-while-making-rest-call-to-server