multipart/form-data POST

Back to HTTP Tutorial Index

A multipart/form-data POST is the typical type of POST for uploading files to a web server. It can also be used in a more general way. A multipart/form-data POST can combine name/value parameters with other data in a multipart MIME request body. Here is an example of a multipart/form-data POST containing some name/value params and some data:

POST /xyz/something HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=------------090708030009010000030901
Content-Length: 2220

--------------090708030009010000030901
Content-Disposition: form-data; name="param1"

value1
--------------090708030009010000030901
Content-Disposition: form-data; name="param2"

value2
--------------090708030009010000030901
Content-Disposition: form-data; name="starfish20"; filename="starfish20.jpg"
Content-Type: image/jpeg

JPEG DATA HERE...
--------------090708030009010000030901
Content-Disposition: form-data; name="helloWorld"; filename="helloWorld.pdf"
Content-Type: application/pdf

PDF DATA HERE...
--------------090708030009010000030901
Content-Disposition: form-data; name="tinyA"; filename="tinyA.xml"
Content-Type: text/xml

XML DATA HERE...
--------------090708030009010000030901--

About the multipart/form-data 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. A MIME message is composed of a header followed by a blank line, followed by the MIME body.
  • In this case, the MIME body is multipart. Each sub-part is delimited by a boundary string. The boundary string in the above example is "------------090708030009010000030901".
  • Chilkat automatically composes and generates the multipart body, including generating a random boundary string.
  • The Content-Type header describes the type of content in the MIME body. The top-level MIME header content-type is "multipart/form-data". Each sub-part can have a Content-Type if needed.
  • Content-Length indicates the exact number of bytes in the full multipart body of the HTTP request (i.e. the length of the entire multipart content that follows the blank line after the outermost/topmost MIME header). 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://example.com/xyz/something". Chilkat always automatically adds the Host header.

Chilkat Examples Implementing the Above multipart/form-data POST

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