Detailed description of Content-Type in http requests, detailed description of content-type

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.