Several common types of content type

Time:2020-11-2

1、application/x-www-form-urlencoded

1) Browser’s native form form form

2) The submitted data is encoded in the way of key1 = val1 & key2 = val2, and both key and val are URL transcoded

3) The data is encoded as name / value pairs. This is the standard code case

2、multipart/form-data

When you need to upload files in the form, you need to use this format. Common media formats are used when uploading files

3、application/json

The message body is a serialized JSON string

4、text/xml

It is a remote call specification that uses HTTP as the transmission protocol and XML as the encoding method

5、text/plain

The data is encoded in plain text (text / JSON / XML / HTML) without any controls or formatting characters

#Difference between application / JSON and application / x-www-form-urlencoded

application/json:

Function: tell the server that the subject content of the request is a string in JSON format, and the server will parse the JSON string,

Benefits: front end personnel do not need to care about the complexity of the data structure, as long as the standard JSON format can be submitted successfully.

application/x-www-form-urlencoded:Is jQuery’s default Ajax request mode

Function: in the request sending process, the data will be serialized in the form of key value pairs? Send it to the server by key1 = value1 & key2 = Value2

Benefits: all browsers support it