October 19, 2024

About

Understanding of Http Request structure would help you to implement code.

For example, It lets you know how to call functions or which order of function to be chosen when you do Http-Request. So, I summarize Basic Structure of Multipart/Form-Data below.

Structure of Header

What is important here is that the header has some important information such as what request you will do, what kind of content-type the data has, and boundary information and content-length. Note that content-length include not only file size but also overall information length including the boundary.

POST /upload HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=123456789
Content-Length: 12345

Structure of Body

The example of structure of body is shown below,

--123456789
Content-Disposition: form-data; name="text_field"
Content-Type: text/plain

This is the content of the text field.

--123456789
Content-Disposition: form-data; name="file1"; filename="example1.txt"
Content-Type: text/plain

File content of example1.txt here

--123456789
Content-Disposition: form-data; name="file2"; filename="example2.txt"
Content-Type: text/plain

File content of example2.txt here

--123456789--