Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Calling API from browser fails but works with Postman

I am trying to execute a simple get request from the browser with the below code:

var url = "https://some-url/gateway/auth/api/v1/userInfo";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.setRequestHeader("Cookie", "cookie"); //I am passing the valid cookie 

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();

I am passing the same cookie for the GET request from POSTMAN and that works. This actually works in the browser too if I open the website, take the cookie from one of the requests and execute the above code in dev tools console.

What I am not able to understand is if I open a blank tab and then in devtools console if I try to execute the same code, it throws a CORS correctly. Now to get past the CORS issue, I have opened chrome and disabled the web security executing something like this chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security from run option.

Once I do this, the call fails with the below error.

Error

Does someone know what could be causing it and how can I fix it?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda