Content-Type field
Content-Type identifies the media type of the representation associated with a message.
- fields
- representations
- media types
Meaning
Content-Type identifies the media type of the representation associated with
the message. The media type tells a recipient what the data format is and how it
is intended to be processed after any Content-Encoding is decoded.
Content-Type: application/json; charset=utf-8
Expected result: the recipient interprets the associated representation as JSON. The parameter is part of the media type; it is not a separate HTTP field.
Requests and responses
On a request with content, Content-Type describes the submitted
representation. It does not state which response formats the client accepts;
that is the role of fields such as Accept. On a response, it describes the
selected representation returned by the server.
A sender that knows the media type should send the field. Missing or incorrect metadata can make a recipient reject the content, treat it as generic binary data, or apply format-sniffing behavior that varies by implementation.
Parameters and content coding
Media-type parameters refine the type. For example, a charset parameter can
identify a character encoding when the media type defines that parameter.
Content-Encoding: gzip is different: it describes an additional coding applied
to the typed representation.
Common mistakes
- Do not use a filename extension as a substitute for the field.
- Do not send JSON as
text/plainmerely to avoid a browser preflight. - Do not confuse
Content-TypewithAcceptorContent-Encoding. - Validate that the body actually conforms to the declared media type.
