Postman returns JSON, but Fetch request returns status 204 in browser

Asked

Viewed 40 times

0

I’m making a request with the function Fetch(), but I always get the same message, with 204 status:

inserir a descrição da imagem aqui

However, when making the request via POSTMAN, I receive status 200, with the necessary information:

inserir a descrição da imagem aqui

My code is here:

fetch(`URL`, {
      method: "GET",
      header: {
        "Access-token": "xxx",
        "Content-Type": "application/json",
      },
    }
  )
  .then((response) => {
    console.log(response)
  })
  .catch((err) => {
    console.error("Erro: ", err);
  });

1 answer

1


It seems that you are being blocked by your browser’s Cors policy. This is probably because an api is being accessed that has a different domain than your fetch code. When you use Postman, there is no blocking by Cors policy.

There are two ways to solve this:

1st: disable your browser’s Cors (not recommended as it is dangerous to surf the web like this)

2nd: on your backend server (referring api you are accessing), put a list of domains allowed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.