Thursday, 18 December 2008

How to use curl to post a SOAP message

Sometimes, it is necessary to send a SOAP request to your web service to test
something out. There are multiple ways to do this - XMLSpy, socat,
netcat etc. but these are sometimes only available on development environments and not on machines where you might actually have to test something out.
That's when we can use curl to do this for us.
For the sense of this post, curl was the only network tool I had at my disposal to do this job but it's pretty handy.

First off, we need a sample SOAP message in a file. We can use curl to deal with the HTTP headers, so we only need the main body of data.





Let's say we store this in soap.req
We can then call our service like this :-

curl -d@soap.req http://someservice:8766

and see the result.

Well, the title says it all. If only I had started this 20 years ago, I would have had a fantastic record of my knowledge growth (and demise) from the start of my IT career to the present. Pretty much all of my wrangling with Linux from its inception would have been here, but there is no point in dwelling on things that haven't happened. I've got to start somewhere ...