Sometimes you may need to post a SOAP request from command line.
This article shows how to do this using the curl command on UNIX systems.

Step 1

Let’s assume the SOAP envelope below is the request you want to post:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:my:service:types">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:Message>
         <urn:Field1>Field 1 value</urn:Field1>
         <urn:Field2>Field 2 value</urn:Field2>
      </urn:Message>
   </soapenv:Body>
</soapenv:Envelope>

What you have to do is create a file with that content. In this example we named the file as “soap_envelope.txt”.

Step 2

Now we gonna to post the request using the curl command.

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE

For example:

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:my:service-interaction:soap:some-action" --data @soap_envelope.txt http://192.168.1.1:8080/myservice

Note: You can add -sL -w "%{http_code} %{url_effective}\\n" option in order to get the HTTP result code.