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

219
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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