BudiBadu Logo
Samplebadu

cURL by Example: XML/SOAP Request

Latest

Send an XML payload, common in legacy SOAP APIs.

Code

# Send XML data
curl -X POST https://api.example.com/soap \
     -H "Content-Type: text/xml" \
     -d '<soap:Envelope>...</soap:Envelope>'

# Read XML from file (recommended)
curl -X POST https://api.example.com/soap \
     -H "Content-Type: text/xml" \
     -H "SOAPAction: http://example.com/GetInfo" \
     -d @request.xml

Explanation

SOAP is an older protocol that uses XML for message format. While most modern APIs use JSON, many enterprise and legacy systems still rely on SOAP.

Key differences between SOAP versions:

  • SOAP 1.1 uses Content-Type: text/xml and requires SOAPAction header
  • SOAP 1.2 uses Content-Type: application/soap+xml and includes action in the content type

The SOAPAction header tells the server which operation you want to perform. Some servers use it for routing, while others require it for compatibility even if they don't use it. Check the WSDL (Web Services Description Language) file for the correct SOAPAction value.

SOAP envelopes can be large and complex. Always store them in external files rather than trying to write them inline. This makes debugging easier and prevents shell escaping issues with special characters.

Code Breakdown

3
Content-Type: text/xml tells the server to parse XML.
8
SOAPAction is a critical header for many SOAP 1.1 services.
9
-d @request.xml keeps complex XML out of the command line.