title: Apache HttpClient POST does not work with entity
body: <p>I developed a simple Java socket-based web server which can read the request from a client. For the client I use the Apache HttpClient library with the following code:</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://localhost:7777/");
  HttpResponse response = httpclient.execute(httppost);
  HttpEntity entity = response.getEntity();
  if (entity != null)
  {
    System.out.println(EntityUtils.toString(entity));
  }
  </code></pre>
  
  <p>When I execute the code, the server gets this request from the client:</p>
  
  <pre><code>POST / HTTP/1.1 
  Content-Length: 0
  Host: localhost:7777 
  Connection: Keep-Alive
  User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
  </code></pre>
  
  <p>This is ok. But now I want to send some data via HTTP-POST so I extended my code:</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://localhost:7777/");
  // Extension:
  StringEntity testString = new StringEntity("Hello World!", "text/plain", "UTF-8");
  httppost.addHeader(testString.getContentType());
  httppost.setEntity(testString);
  //
  HttpResponse response = httpclient.execute(httppost);
  HttpEntity entity = response.getEntity();
  if (entity != null)
  {
    System.out.println(EntityUtils.toString(entity));
  }
  </code></pre>
  
  <p>If I execute the code now, nothing goes to the server. If I remove "httppost.setEntity(testString);" everything will work like described in the beginning. So the problem must be at "httppost.setEntity(testString);". </p>
  
  <p>Does anyone know why nothing is sent when I use "setEntity"? Is there another way to transfer the data? I already tried this example: <a href="http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java" rel="nofollow">http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java</a> but without success.</p>
  
  <p>Perhaps the problem lies on my webserver. How should a response for a successful request look like? 
  I use this message:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Server: RAKETE Web server/0.1 (Java)
  Content-Length: 2
  Connection: close
  Content-Type: text/html
  </code></pre>