This is a HTTP POST request sent with the request body specially formatted as a series of “parts”, separated by a boundary string. It allows a mix for form data, files etc to be sent as a HTTP POST.

Resources

https://ec.haxx.se/http-multipart.html

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

Example 1

Form
<form action="my_post_page.php" method="post" enctype="multipart/form-data">

</form> 
html that is sent
POST /submit.cgi HTTP/1.1
Host: example.com
User-Agent: curl/7.46.0
Accept: */*
Content-Length: 313
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----MyFormBoundaryvZ0ZHShNAcBABWFy
------MyFormBoundaryvZ0ZHShNAcBABWFy
Content-Disposition: form-data; name="UserName"

Hello
------MyFormBoundaryvZ0ZHShNAcBABWFy
Content-Disposition: form-data; name="fileToUpload"; filename="file.txt"
Content-Type: text/plain

The contents of this file
------MyFormBoundaryvZ0ZHShNAcBABWFy--

Boundaries – IMPORTANT NOTE!!!!

All boundaries start with two hyphens (–). The final boundary also concludes with two hyphens (–).

When you place the boundary (e.g. “—-MyFormBoundaryvZ0ZHShNAcBABWFy”) you add two hyphens before it (so in this example “—-MyFormBoundaryvZ0ZHShNAcBABWFy” becomes “——MyFormBoundaryvZ0ZHShNAcBABWFy”). For the last one you also add two hyphens after it. This can be confusing when looking at examples (like above) because several hyphens are often chosen to be part of the boundary string (which can be anything you want)!

File content type

Examples: text/plain, text/csv, image.jpeg, application/octet-stream

Line breaks

You need to use “\r\n”, using “\n” will give you a 500 server error response (on some servers at least).

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *