47

Do you guys know how I can use the Curl command line to POST SOAP to test a web service?

I have a file (soap.xml) which has all the soap message attached to it I just don't seem to be able to properly post it.

Thanks!

Jason Etheridge
  • 6,849
  • 5
  • 30
  • 33
el_eduardo
  • 3,138
  • 4
  • 21
  • 17

5 Answers5

43

Posting a string:

curl -d "String to post" "http://www.example.com/target"

Posting the contents of a file:

curl -d @soap.xml "http://www.example.com/target"
lbz
  • 9,560
  • 2
  • 30
  • 35
  • 22
    Usually this header is also necessary: -H "Content-Type: application/soap+xml;charset=UTF-8" – tokland Sep 15 '10 at 15:14
  • 2
    Getting `HTTP/1.1 415 Unsupported Media Type` means the content-type header is missing or wrong. Try one of the ones suggested here (`application/soap+xml` didn't work for me, but `text/xml` worked) – Nickolay Jun 11 '14 at 09:27
  • 1
    I also had to add `; action=http://tempuri.org/WhateverAction` to the `Content-Type` header. – Egor Tensin Jan 16 '15 at 12:14
34

For a SOAP 1.2 Webservice, I normally use

curl --header "content-type: application/soap+xml" --data @filetopost.xml http://domain/path
Kris C
  • 2,828
  • 1
  • 29
  • 25
27

Wrong. That doesn't work for me.

For me this one works:

curl 
-H 'SOAPACTION: "urn:samsung.com:service:MainTVAgent2:1#CheckPIN"'   
-X POST 
-H 'Content-type: text/xml'   
-d @/tmp/pinrequest.xml 
192.168.1.5:52235/MainTVServer2/control/MainTVAgent2
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Zibri
  • 9,096
  • 3
  • 52
  • 44
8
curl -H "Content-Type: text/xml; charset=utf-8" \
-H "SOAPAction:" \
-d @soap.txt -X POST http://someurl
Ahmet Karakaya
  • 9,899
  • 23
  • 86
  • 141
4

If you want a fluffier interface than the terminal, http://hurl.it/ is awesome.

oliland
  • 1,299
  • 11
  • 23