Detailed description of Content-Type in http requests, detailed description of content-type
Detailed description of Content-Type in http requests
The Content-Type field in the http header specifies the HTTP body Content Encoding Type of the request and response. The client and server correctly decode the http body Content based on the Content-Type field in the HTTP header.
Common http header Content-Type:
* application/x-www-form-urlencoded * multipart/form-data * application/json * application/xml
Example
* The frontend uses Content-Type: "application/json" to encode the http request Content and submit it to the server. The server uses Content-Type: "application/json" to decode the http request Content.
If the http Request header Content-Type is not explicitly specified, the application/x-www-form-urlencoded; charset = UTF-8 is used as the default value, and the backend method cannot decode Content-Type: application/x-www-form-urlencoded http Request body content. It also indicates that the backend method can only decode the http Request body whose Content-Type is application/json in the Request header.
* The server uses Content-Type: "application/json" to encode the http response body Content and returns it to the front end. The front end uses Content-Type: "application/json" to decode the http response body Content.
* The server returns Response Content-Type: application/json. The value of the front-end ype is not specified. In this case, the http response body content is decoded. The data type is Object.
* The server does not return Response Content-Type: application/json. the value specified by the front-end dataType is json. When the http response body content is decoded, the data type is Object.
* The server does not return Response Content-Type: application/json, and the front-end ype does not specify the value "json ". In this case, the json String of the http response body cannot be decoded. The data type is String.
If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!