Messages, representations and files
Headers and content negotiation
Separate preferred format from actual format.
Understand the concept
Accept expresses preferred response media types; Content-Type describes the actual body. Requesting JSON does not make a request body JSON. Language and compression preferences have their own fields and must be supported deliberately.
Vary tells caches which request fields distinguish representations. Omitting language from a language-dependent cache key can distribute the wrong translation. Vary: * greatly limits reuse.
Header names are case-insensitive, but value rules are field-specific. Align size limits across clients, proxies and servers. Reject control characters when reflecting untrusted data into fields.
Support bilingual representations and diverse clients.
Interchanging Accept and Content-Type.
One topic. Three levels of depth.
Accept: application/jsonResponse preference.
This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.
Try it yourself first.
Which fields describe a JSON POST body and preferred PDF response?
Show the solution and explanation
Content-Type: application/json
Accept: application/pdfThe server must support the combination; headers do not create support.