Axios post sending body but body is undefined with fetch and Postman

fetch doesn’t default to posting JSON, which is why you had to encode the body explicitly. You also need to tell the server that you are sending JSON.

You can’t do that without permission from CORS, so you must not set the mode to no-cors.

const headers = new Headers();
headers.append("Content-Type", "application/json");

fetch("http://localhost:3000/login", {
  method: "POST",
  body: JSON.stringify({ user: "Fred", password: "Flintstone" }),

The problem with Postman is probably the same (but not visible in the UI screenshot): You need to set the Content-Type header.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top