Why does setting Content-Type: application/json trigger a CORS preflight?
Because `application/json` is not a CORS-safelisted content type. Your server must answer the `OPTIONS` preflight with `Access-Control-Allow-Headers: Content-Type`.
HTTP 415 Unsupported Media Type means the server refused the payload because the request's `Content-Type` or `Content-Encoding` header is not supported by the endpoint.
// Browser fetch for JSON
await fetch('https://api.example.com/v1/items', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'widget' }),
});
// Note: For FormData uploads, DO NOT manually set Content-Type!
curl -i -sS -X POST -H 'Content-Type: application/json' -d '{"name":"widget"}' https://api.example.com/v1/items
Because `application/json` is not a CORS-safelisted content type. Your server must answer the `OPTIONS` preflight with `Access-Control-Allow-Headers: Content-Type`.
Manually setting `Content-Type: multipart/form-data` omits the required `; boundary=----...` token. Omit the header and let `fetch()` set it automatically.
Return `Accept-Post: application/json` or an RFC 9457 error body listing accepted media types.