Problems caused by different Content-types in HTTP.

Foreword:

      The reason why I came to study this thing is because I encountered a problem more than once: the front-end passed parameters (you can see that it was passed in the browser), but the back-end did not receive it . At first, I encountered it with axios and the backend of writing go, and then I encountered it again with vue-resource and the backend of writing java. The strange thing is that I have no problem using native ajax to request. Later, when I used postman to test, I found that there seemed to be some differences in their Content-type. I probably knew the reason, but I didn't go into it because I was lazy. But recently my colleague encountered it again, which made me more diligent and simple to use. node to test it.

 

--------------------------------------------- Dividing line--- ------------------------------------------

 

There are three commonly used Content-types: application/x-www-form-urlencoded     |    application/json     |    multipart/form-data

First look through the browser to see what they look like when they transmit the data

application/x-www-form-urlencoded as shown in the figure:

 

application/json as shown in the figure:

 

 

Comparing these two places reveals that the way they transmit data is different. The former is the way of using  urlencoded  , which is  'msg=send&id=1';

The latter uses the json format , which is directly a json string, that is, JSON.stringify({msg: "send json"});

//urlencoded format
xmlHttp.send('msg=send&id=1')
//json format
xmlHttp.send(JSON.stringify({msg: "send json"}));

  ---------------Unfinished, want to sleep---------------

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325223933&siteId=291194637