A fetch POST from React comes back as 415 Unsupported Media Type
415 Unsupported Media TypeShort answer
A 415 means the server refused the request body because of its format, not because the data is wrong. The usual cause is the Content-Type header: it is missing, names another format than the body, has a typo in the charset, or does not match what the endpoint accepts. Read the Accept-Post header in the response, then send exactly that type.
Fix it fast
1Find out which cause you have
Open the failed request in the browser Network tab, or repeat it with curl, and read the response headers. Some servers state the type they want in Accept-Post. Compare it with the Content-Type you sent.
curl -i -X POST https://example.com/api/items \ -H "Content-Type: application/json" \ -d '{"name":"test"}'2Match what you see, then jump to its fix
- 1
415 on every POST; the request shows a Content-Type that is missing or is not the format of the body (for example a JSON body labelled application/x-www-form-urlencoded)The Content-Type header does not describe the body you sendFix - 2
415 although the header looks right at a glance, for example charset=UTF8The media type string is written in a form the server does not acceptFix - 3
415 only on one route; the controller action has a [Consumes] attribute naming a different typeThe endpoint accepts only another content type, so the action is not matchedFix
- 1
What does the error look like?
415 Unsupported Media TypeAccept-Post: application/json; charset=UTF-8
Cause 1 of 3
The Content-Type header does not describe the body you send
1Check
In the Network tab, open the request and read Request Headers. The Content-Type must match the body: JSON text needs application/json. A request that carries JSON but is labelled as a form is refused with 415.
// in the browser console, on the page that sends the request
// (replace the URL with your endpoint)
fetch('/api/items', {
method: 'POST',
body: JSON.stringify({ name: 'test' }),
}).then(r => console.log(r.status, r.headers.get('Accept-Post')));2Fix
Set the header yourself and send the body as a JSON string.
const response = await fetch('/api/items', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'test' }),
});
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}3Verify
The same request now returns a 2xx status in the Network tab.
curl -i -X POST https://example.com/api/items -H "Content-Type: application/json" -d '{"name":"test"}'Confirmed by developer.mozilla.org
Cause 2 of 3
The media type string is written in a form the server does not accept
1Check
Servers can be strict about the exact text. Writing UTF8 instead of UTF-8 for the charset can make the server treat the whole media type as invalid. Look for a charset parameter in the header your code or an axios or fetch wrapper sets.
grep -rn "charset" src/2Fix
Use the standard spelling, or drop the charset parameter and send application/json alone.
headers: { 'Content-Type': 'application/json; charset=UTF-8' }3Verify
Repeat the request and confirm the status is no longer 415.
curl -i -X POST https://example.com/api/items -H "Content-Type: application/json; charset=UTF-8" -d '{"name":"test"}'Confirmed by developer.mozilla.org
Cause 3 of 3
The endpoint accepts only another content type, so the action is not matched
1Check
On an ASP.NET Core API, an action marked [Consumes(...)] accepts only the listed Content-Type, and any other request gets 415. Without the attribute, the Content-Type header decides which input formatter reads the body. Look at the action you call.
grep -rn "Consumes" Controllers/2Fix
Send the type the action names. If the action should take JSON, change the attribute to application/json. If it should take a form, send a form body with the form content type instead of JSON.
// C#
[Consumes("application/json")]
[HttpPost]
public IActionResult Create([FromBody] Item item) => Ok(item);3Verify
Call the route again with the type the attribute lists and check for a 2xx response.
curl -i -X POST https://localhost:5001/api/items -H "Content-Type: application/json" -d '{"name":"test"}'Confirmed by learn.microsoft.com
How do I stop it coming back?
- Wrap fetch in one helper that always sets Content-Type for JSON requests, so no call site forgets it.
- Check response.ok after every fetch, because fetch does not reject on a 415 or any other HTTP error status.
- Return Accept-Post (or document the accepted types) from your own API so clients can see what to send.
- Test new endpoints with curl and an explicit Content-Type before writing the React code.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Browser blocks a JSON request: Content-Type is not allowed by Access-Control-Allow-Headers
Reason: missing token 'content-type' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel
Content-Type: application/json is not on the browser's no-preflight list, so the browser sends an OPTIONS request first and asks for content-type.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix