content
Content-Type
Declares the media type of the body in both requests and responses, and often carries additional parameters like charset or boundary. Governs how the recipient parses or renders the payload.
Content-Type: <type>/<subtype>[; parameter=value ...] (e.g. application/json; charset=utf-8, multipart/form-data; boundary=...) Common directives / values
| Directive | Purpose |
|---|---|
| application/json | JSON payloads; charset is UTF-8 by definition (RFC 8259). |
| text/html; charset=utf-8 | HTML documents — always declare a charset. |
| application/x-www-form-urlencoded | Classic HTML form submissions. |
| multipart/form-data; boundary=<b> | File uploads — the boundary parameter delimits parts. |
| application/octet-stream | Arbitrary binary — often triggers a download. |
| text/event-stream | Server-Sent Events (SSE) streaming responses. |
Examples
Content-Type: application/json JSON API request or response body.
Content-Type: text/html; charset=utf-8 Standard HTML page — the charset param prevents mojibake.
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk Browser file upload; boundary separates parts inside the body.
Content-Type: application/pdf PDF response — combine with Content-Disposition to force download or inline view.
Gotcha
Missing or wrong Content-Type combined with X-Content-Type-Options: nosniff will cause the browser to refuse the resource (blocked stylesheet/script). Never add charset to application/json — the spec forbids it (though most parsers ignore it).
Related headers
Content-Length
Number of octets in the message body, letting the recipient know exactly where the message ends. Required for most requests with bodies unless Transfer-Encoding: chunked is used.
Content-Encoding
Indicates that the body has been transformed with one or more compressions and must be decoded in reverse order to recover the original payload. Negotiated via the client's Accept-Encoding.
Content-Disposition
In responses, controls whether the browser renders the body inline or offers it as a download, and suggests a filename. In multipart/form-data request parts, names the form field and optionally the upload filename.
Accept-Encoding
Client advertisement of which content codings it can decode, letting the server compress the response accordingly. Absence means 'identity only'; an explicit identity;q=0 forbids uncompressed responses.