Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda