title: Sending HTTP Post request with SOAP action using org.apache.http
body: <p>I'm trying to write a hard-coded HTTP Post request with SOAP action, using the org.apache.http api.
  My problem is I didn't find a way to add a request body (in my case - SOAP action).
  I'll be glad for some guidance.</p>
  
  <pre><code>import java.net.URI;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.impl.client.RequestWrapper;
  import org.apache.http.protocol.HTTP;
  
  public class HTTPRequest
  {
      @SuppressWarnings("unused")
      public HTTPRequest()
      {
          try {
              HttpClient httpclient = new DefaultHttpClient();
              String body="DataDataData";
              String bodyLength=new Integer(body.length()).toString();
              System.out.println(bodyLength);
  //          StringEntity stringEntity=new StringEntity(body);
  
              URI uri=new URI("SOMEURL?Param1=1234&amp;Param2=abcd");
              HttpPost httpPost = new HttpPost(uri);
              httpPost.addHeader("Test", "Test_Value");
  
  //          httpPost.setEntity(stringEntity);
  
              StringEntity entity = new StringEntity(body, "text/xml",HTTP.DEFAULT_CONTENT_CHARSET);
              httpPost.setEntity(entity);
  
              RequestWrapper requestWrapper=new RequestWrapper(httpPost);
              requestWrapper.setMethod("POST");
              requestWrapper.setHeader("LuckyNumber", "77");
              requestWrapper.removeHeaders("Host");
              requestWrapper.setHeader("Host", "GOD_IS_A_DJ");
  //          requestWrapper.setHeader("Content-Length",bodyLength);          
              HttpResponse response = httpclient.execute(requestWrapper);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>