Four formats of Http Body

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?

image-20210129180306059

2.1、form-data

form-data The role of

form-dataIt is in the Http protocol, multipart/form-datawhich 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-datatransmission string key pair

Select the format of Body in Postman as form-data

image-20210129183931356

Content-TypeField value multipart/form-dataand use boundaryas a border to divide each pair of key-valuekey-value pairs

image-20210130090417707

Use form-datafile 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

image-20210129182954381

Content-TypeField value multipart/form-data, and use boundaryas a border to divide each pair of key-valuekey-value pairs (file and the file name can also be seen as key-valuethe relationship between key-value pairs)

image-20210129183354826

Using form-datasimultaneous transmission of strings and key file

Select the format of Body in Postman form-data, add string key-value pairs and files

image-20210129210327861

Now, in fact, there is no difference between transferring files and transferring string key-value pairs~~~

image-20210129210606072

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

image-20210129211005840

Content-TypeField has a value application/x-www-form-urlencoded, parameter submitted form in key-valuethe form of key-value pairs is encapsulated in the request body

image-20210129211057478

2.3、raw

raw The role of

You can upload text in any format

  1. Select text, the request header is:text/plain
  2. Select javascript, the request header is:application/javascript
  3. Selected json, the request header is: application/json(if you want to jsonformat parameter passing, to use raw+jsonon the line)
  4. Select html, the request header is:text/html
  5. Select application/xml, the request header is:application/xml

image-20210129211758647

Demos rawtransmission jsonstring

Select the format of Body in Postman raw, and selectapplication/json

image-20210129211930198

Content-TypeThe value of the field application/json, the content of the request body is the json string we filled in

image-20210129212322247

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 binarytransfer a single file

Select the format of Body in Postman binary, and select the file to upload

image-20210129212649899

Content-TypeThe value of the field is application/jsonthat only one file is transferred, so the content of the request body is the content of the file

image-20210129212806622

Guess you like

Origin blog.csdn.net/oneby1314/article/details/113406924