Skip to main content
HTTP

Content-Type and MIME types: what the header controls and why charset breaks JSON parsers

Set the media type for the bytes you send, let the browser generate multipart boundaries, and treat charset as part of a text contract.

Thien Nguyen
By Thien Nguyen
Updated July 21, 2026 · 1 min read

Content-Type tells the recipient how to interpret the bytes in a message. It is not a filename hint and it is not what the client hopes to receive—that is Accept. Mixing those two headers is behind a surprising number of 406 and 415 incidents.

Send the exact representation

BodyContent-TypeDetail that matters
API JSONapplication/jsonSend JSON bytes, not a JavaScript object
HTMLtext/html; charset=utf-8Declare text encoding deliberately
CSStext/cssBrowsers may refuse incorrectly typed styles
PNGimage/pngDo not claim JPEG from the extension
Form with filesbrowser-generated multipartBoundary is required
await fetch('/api/orders', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ sku: 'red-mug' }),
});

Let FormData own its boundary

const form = new FormData();
form.append('receipt', file);
await fetch('/api/receipts', { method: 'POST', body: form });

Do not add Content-Type: multipart/form-data yourself. The browser creates a boundary such as ----WebKitFormBoundary…; omitting it makes the server unable to split parts.

JSON uses Unicode and is ordinarily exchanged as UTF-8. If a client receives unexpected characters, inspect the actual response bytes and header before “fixing” the JSON parser.

Do not trust uploads by their label

An upload can claim image/png while containing HTML or executable content. Where security matters, inspect the file signature, store untrusted uploads separately, and serve them with X-Content-Type-Options: nosniff. The header is a useful contract between cooperative systems, not proof that an attacker supplied truthful bytes.

References

Primary documentation and specifications checked when this article was last updated.

HTTPAPIsWeb

Related articles

All articles