Four formats of Http Body
1. Reference materials
Several data formats of http request body
Multipart/form-data request analysis of HTTP protocol
2. Four formats of Http Body
There are four formats such body at the request of the Postman: form-data
, , x-www-from-urlencoded
, raw
,binary
this four formats, respectively, represent?
2.1、form-data
form-data
The role of
form-data
It is in the Http protocol, multipart/form-data
which means submitting in the form of a form, it will process the data of the form into a message, with tags as the unit, separated by separators. You can upload key-value pairs or files.
Use
form-data
transmission string key pair
Select the format of Body in Postman as form-data
Content-Type
Field value multipart/form-data
and use boundary
as a border to divide each pair of key-value
key-value pairs
Use
form-data
file transfer
How to transfer files in Postman? Select the format of Body in Postman form-data
, and select [File] when entering Key to upload the file
Content-Type
Field value multipart/form-data
, and use boundary
as a border to divide each pair of key-value
key-value pairs (file and the file name can also be seen as key-value
the relationship between key-value pairs)
Using
form-data
simultaneous transmission of strings and key file
Select the format of Body in Postman form-data
, add string key-value pairs and files
Now, in fact, there is no difference between transferring files and transferring string key-value pairs~~~
2.2、x-www-from-urlencoded
x-www-from-urlencoded
The role of
application/x-www-from-urlencoded
Will convert the data in the form into key-value pairs, such as name=oneby&hobby=coding
Demo
x-www-from-urlencoded
Select the format of Body in Postman as x-www-from-urlencoded
Content-Type
Field has a value application/x-www-form-urlencoded
, parameter submitted form in key-value
the form of key-value pairs is encapsulated in the request body
2.3、raw
raw
The role of
You can upload text in any format
- Select
text
, the request header is:text/plain
- Select
javascript
, the request header is:application/javascript
- Selected
json
, the request header is:application/json
(if you want tojson
format parameter passing, to useraw+json
on the line) - Select
html
, the request header is:text/html
- Select
application/xml
, the request header is:application/xml
Demos
raw
transmissionjson
string
Select the format of Body in Postman raw
, and selectapplication/json
Content-Type
The value of the field application/json
, the content of the request body is the json string we filled in
2.4、binary
binary
The role of
binary
Usually used to upload files, because there is no key value, only one file can be uploaded at a time (generally not much)
Demos
binary
transfer a single file
Select the format of Body in Postman binary
, and select the file to upload
Content-Type
The value of the field is application/json
that only one file is transferred, so the content of the request body is the content of the file