title: Java HTTPPost Request with Apache HttpClient
body: <p>I need a java program to generate the following request.
  I am using Apache HttpClient Library but still not able to produce a request like this:</p>
  
  <p>This is what my python program generates and i wrote an equivalent java program. but its throwing 403.</p>
  
  <p>2012-09-10 15:12:05G INFO: G2OAuth auth data = "3, 0.0.0.0, 0.0.0.0, 1347289925, 3223833979, crlakamai"
  2012-09-10 15:12:05G INFO: G2OAuth sign string = "3, 0.0.0.0, 0.0.0.0, 1347289925, 3223833979, akamai/182228\nx-akamai-acs-action:version=1&amp;action=dir&amp;format=xml\n"</p>
  
  <pre><code>   send: 'POST /182228 HTTP/1.1\r\nHost: crl.api.akamailab.com\r\nAccept-Encoding: identity\r\nX-Akamai-ACS-Auth-Data: 3, 0.0.0.0, 0.0.0.0, 1347289925, 3223833979, crlsymc\r\nX-Akamai-ACS-Auth-Sign: eFnWtJBIyj4rxV3V0axF3w==\r\nX-Akamai-ACS-Action: version=1&amp;action=dir&amp;format=xml\r\n\r\n'
  
  reply: 'HTTP/1.1 200 OK\r\n'
  header: Server: Apache
  header: Content-Type: text/html
  header: Date: Mon, 10 Sep 2012 15:12:09 GMT
  header: Content-Length: 31
  header: Connection: keep-alive
  </code></pre>
  
  <p>The response looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;stat directory="/182232"&gt;
          &lt;file type="file" name="log4j.properties" mtime="1346780907" size="301" md5="c92268157f1732a05c2027d151fc539a"/&gt;
  &lt;/stat&gt;
  </code></pre>
  
  <p>Here is My Java Code:</p>
  
  <pre><code>    final HttpHost targetHost = new HttpHost("a.host.com", 80, "http");
      final DefaultHttpClient httpClient = new DefaultHttpClient();
      final Credentials credentials = new UsernamePasswordCredentials("user","pass");
      httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials);
  
  
      final HttpPost httpPostRequest = new HttpPost("akamai/182232");
  
      //Add your Data
      final List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(6);
      nameValuePairs.add(new BasicNameValuePair("Host: ", "a.host.com");
      nameValuePairs.add(new BasicNameValuePair("Accept-Encoding: ", "identity"));
      nameValuePairs.add(new BasicNameValuePair("Content-Length: ", "6"));
  
      httpPostRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
      final HttpResponse response = httpClient.execute(targetHost, httpPostRequest);
  
      if (response.getStatusLine().getStatusCode() != 200) {
          throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
      }
  </code></pre>
  
  <p>My response looks like this.</p>
  
  <pre><code>2012-09-10 11:31:22,600 DEBUG [wire] &gt;&gt; "POST /182228/a.crl HTTP/1.1[\r][\n]"
  2012-09-10 11:31:22,601 DEBUG [wire] &gt;&gt; "Content-Length: 394[\r][\n]"
  2012-09-10 11:31:22,601 DEBUG [wire] &gt;&gt; "Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1[\r][\n]"
  2012-09-10 11:31:22,601 DEBUG [wire] &gt;&gt; "Host: crl.api.symclab.com:80[\r][\n]"
  2012-09-10 11:31:22,601 DEBUG [wire] &gt;&gt; "Connection: Keep-Alive[\r][\n]"
  2012-09-10 11:31:22,601 DEBUG [wire] &gt;&gt; "User-Agent: Apache-HttpClient/4.1.3 (java 1.5)[\r][\n]"
  2012-09-10 11:31:22,602 DEBUG [wire] &gt;&gt; "[\r][\n]"
  </code></pre>
  
  <p>I want Accept-Encoding another headers as part of post, how do i add them ? It hast to be part of the post request i believe and not http header.</p>