title: Sending request to SOAP web service using Apache http client
body: <p>I am writing a Java code using <code>Apache httpclient</code> to call SOAP web service. So far I have written the below piece of code which is working fine.</p>
  <pre><code>void post(String strURL, String strSoapAction,  String strXMLFilename) throws Exception{
          
          File input = new File(strXMLFilename);
          PostMethod post = new PostMethod(strURL);
          RequestEntity entity = new FileRequestEntity(input, &quot;text/xml; charset=ISO-8859-1&quot;);
          post.setRequestEntity(entity);
          post.setRequestHeader(&quot;SOAPAction&quot;, strSoapAction);
          HttpClient httpclient = new HttpClient();
          try {
              int result = httpclient.executeMethod(post);
              System.out.println(&quot;Response status code: &quot; + result);
              System.out.println(&quot;Response body: &quot;);
              System.out.println(post.getResponseBodyAsString());
          } finally {
              post.releaseConnection();
          }
      }
  </code></pre>
  <p>Here, <strong>strXMLFilename</strong> is SOAP request file taken from SOAP UI (I copied SOAP UI request XML and paste it in some new XML file and then used it).
  The above tests a service that takes String as an argument.</p>
  <p>But now my question is will it be able to test a service that is taking File as an input? I need to send a File to the service. In SOAP UI, I am able to attach a file and test the service but not able to do the same with the above piece of code.</p>