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

224
Vistas
Http request info shows up as blank on server

I am using an express router to receive http post request at location + "/info". The code for that looks like this

let http = new XmlHttpRequest();
http.open("POST",location + "/info"); 
http.send(JSON.stringify(obj));

this is what obj looks like

class Obj{
size = "";
length = ""; 
constructor(size, length)
{
this.size = size;
this.length = length;
}
}
let obj = new Obj("test1","test2");

The code I am using to set up the router is this

router.post("/info", (req,res)=>{
console.log(req.body);
res.send(req.body);
})

When I logged the body of the request, it returned a blank array. How do I fix this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem you are facing results in you not having a header. Without the header, the server won't know how to process the information given in the body.

To create the header, you can use the following code bellow

http.setRequestHeader("Content-type", "application/json");

This will tell the server to process the information as json, and the console will log the object.

about 4 years ago · Juan Pablo Isaza Denunciar
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