title: Problem gzipping HttpPost body using Apache Client 4.1.1
body: <p>I need to send a HTTPPost with body gzipped, the server accepts non gzipped data also but would prefer it gzipped, so Im trying to convert some existing workign code to use gzip
  The data is currently set with</p>
  
  <pre><code>    httpMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  </code></pre>
  
  <p>Ive tried sublclassing  HttpEntityWrapper</p>
  
  <pre><code>static class GzipWrapper extends HttpEntityWrapper
  {
      public GzipWrapper(HttpEntity wrapped)
      {
          super(wrapped);
      }
  
      public void writeTo(OutputStream outstream)
           throws IOException
      {
          GZIPOutputStream gzip = new GZIPOutputStream(outstream);
          super.writeTo(gzip);
      }
  }
  </code></pre>
  
  <p>and changed to </p>
  
  <pre><code>    httpMethod.setEntity(new GzipWrapper(
            new UrlEncodedFormEntity(nameValuePairs)));
  </code></pre>
  
  <p>and added</p>
  
  <pre><code>    if (!httpMethod.containsHeader("Accept-Encoding"))
      {
          httpMethod.addHeader("Accept-Encoding", "gzip");
      }
  </code></pre>
  
  <p>but now my request just time outs I think there must be something wrong with my GZIpWrapper but Im not sure what.</p>
  
  <p>On another note I looked at the <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientGZipContentCompression.java" rel="nofollow">http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientGZipContentCompression.java</a>. example. Aside from the fact that I dont like interceptors because it is difficult to follow program flow it doesnt make sense to me because the request header is set to tell the server to accept gzip data but nowhere does it actually gzip encode any data, it only unzips the response.</p>