title: How to get RestSharp to properly deflate compressed HTTP response?
body: <p>I'm using <a href="http://restsharp.org/" rel="nofollow">RestSharp</a> to make a call to REST service. My call looks something like this:</p>
  
  <pre><code>var request = new RestRequest("/foo", Method.POST);
  request.JsonSerializer.ContentType = "application/json; charset=utf-8";
  request.AddJsonBody(new string[] { "param1", "param2" });
  var response = this._client.Execute&lt;Foo&gt;(request);
  </code></pre>
  
  <p>For most other calls this works fine. I'm running into issues when the response is compressed. The headers in the response look (mostly) like this:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Uncompressed-Size: 35000
  Content-Length: 3019
  Content-Encoding: deflate
  Content-Type: application/json
  </code></pre>
  
  <p>The issue is when I call this method with RestSharp I keep getting the error:</p>
  
  <blockquote>
    <p>Error: Block length does not match with its complement.</p>
  </blockquote>
  
  <p>I've tried setting the <code>Accept-Encoding</code> header in the request but it still produces the error. I also tried using a custom deserializer but the error is occurring before deserialization. From what I can tell, RestSharp should automatically handle deflation if the <code>Content-Encoding</code> header says <code>deflate</code> (which it does).</p>
  
  <p>How can I get RestSharp to handle the deflation properly?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>In the end I was able to have the service changed to look for an <code>Accept-Encoding</code> header in the request with a value of <code>identity</code>. If found, the service was changed to return the data uncompressed.</p>
  
  <p>This is unfortunately not really a solution to the original issue but it does resolve the problem for me. If a better solution is posted I will try it.</p>