HTTP POST with a XML Body

Back to HTTP Tutorial Index

An HTTP POST containing a XML body looks something like this:

POST /StockQuote HTTP/1.1
Host: www.example.org
Accept: */*
Accept-Encoding: gzip
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
SOAPAction: http://www.example.org/StockPrice

<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

About the XML HTTP POST

  • The 1st line is the HTTP start line. It contains the HTTP verb ("POST"), followed by the path part of the URL, and finally the HTTP protocol version.
  • Following the start line, we have standard MIME. HTTP requests and responses are MIME, just like emails are MIME. A MIME message is composed of a header followed by a blank line, followed by the MIME body. In this case, the MIME body will be the XML document.
  • The Content-Type header describes the type of content in the MIME body. Common content types for XML are "application/xml", "text/xml", and "application/soap+xml".
  • Content-Length indicates the exact number of bytes in the body of the HTTP request (i.e. the length of the content that follows the blank line). Chilkat always automatically computes and adds the Content-Length header for you.
  • The Host header is the domain part of the URL. In the above example, the URL would be "https://www.example.org/StockQuote". Chilkat always automatically adds the Host header.
  • The Accept and Accept-Encoding headers are automatically added by Chilkat, but can be changed by your app or suppressed. They tell the server information about what kinds of responses are acceptable.
  • The SOAPAction header is typical of SOAP XML requests. (SOAP requests are a common type of HTTP POST with an XML body.)
  • You can generate source code from a raw HTTP request using Chilkat's online tool at https://tools.chilkat.io/httpRequestToCode.

CURL

A CURL statement to send the above HTTP request is shown here. You can generate source code from a CURL statement using Chilkat's online tool at https://tools.chilkat.io/curlHttp

curl -X POST https://example.com/StockQuote \
  -H "Accept: *.*" \
  -H "Accept-Encoding: gzip" \
  -H "Host: www.example.org" \
  -H "Content-Type: application/soap+xml; charset=utf-8" \
  -H "SOAPAction: http://www.example.org/StockPrice" \
  -d '<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>'

Chilkat Examples Implementing the Above XML POST

Android™ HTTP POST with XML Body
Classic ASP HTTP POST with XML Body
AutoIt HTTP POST with XML Body
C HTTP POST with XML Body
Chilkat2-Python HTTP POST with XML Body
C++ HTTP POST with XML Body
C# HTTP POST with XML Body
DataFlex HTTP POST with XML Body
Delphi ActiveX HTTP POST with XML Body
Delphi DLL HTTP POST with XML Body
.NET Core C# HTTP POST with XML Body
Visual FoxPro HTTP POST with XML Body
Go HTTP POST with XML Body
Java HTTP POST with XML Body
Mono C# HTTP POST with XML Body
Node.js HTTP POST with XML Body
Objective-C HTTP POST with XML Body
Perl HTTP POST with XML Body
PHP ActiveX HTTP POST with XML Body
PHP Extension HTTP POST with XML Body
PowerBuilder HTTP POST with XML Body
PowerShell HTTP POST with XML Body
PureBasic HTTP POST with XML Body
CkPython HTTP POST with XML Body
Ruby HTTP POST with XML Body
SQL Server HTTP POST with XML Body
Swift HTTP POST with XML Body
Tcl HTTP POST with XML Body
Unicode C HTTP POST with XML Body
Unicode C++ HTTP POST with XML Body
Visual Basic 6.0 HTTP POST with XML Body
VB.NET HTTP POST with XML Body
VBScript HTTP POST with XML Body
Xojo Plugin HTTP POST with XML Body