Error Encyclopedia
400

Invalid Content-Type Header Error

Fix 'Invalid Content-Type' errors when the request Content-Type header does not match the request body format.

What Does This Error Mean?

The 'Invalid Content-Type' error occurs when the Content-Type header in a request does not match the actual format of the request body, or the server does not support the specified media type.

Common Causes

1

Sending JSON body with Content-Type: application/x-www-form-urlencoded

2

Forgetting to set Content-Type header at all

3

Typo in the content type string (e.g., 'application/json' instead of 'application/json')

4

Using text/plain when server expects application/json

5

Not including charset with Content-Type when required

How to Fix It

Set correct Content-Type for your body format

Match the Content-Type header to the actual format of your request body.

// JSON body
fetch("/api/data", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ key: "value" }) // ✅ Correct
})

// Form data (let browser set Content-Type automatically)
const formData = new FormData()
formData.append("file", fileInput.files[0])
fetch("/api/upload", { method: "POST", body: formData }) // ❌ Don't set Content-Type manually for FormData

Check for typos

Even a small typo in Content-Type will cause it to be unrecognized.

// ❌ Common typos
"application/json"     // extra double quote
"application/json"     // missing slash
"applicaiton/json"     // misspelled
"Application/JSON"     // wrong case

// ✅ Correct
"application/json"
"application/x-www-form-urlencoded"
"multipart/form-data"

Verify server expectations

Check API documentation for the exact Content-Type the server expects.

// API expects
Content-Type: application/json

// But you sent
Content-Type: text/plain
{"key": "value"}

// Server cannot parse plain text as JSON → 400 or 415

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category: