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

135
Visualizações
Axios not sending body

Axios not sending body to my API.

router.get('/login', async function(req,res) {
  try {
    const email  = req.body.email;
    const pass  = req.body.pass;
    const users = await pool.query("select username from users where username=$1 and password=$2", [email, pass]);
    if(users.rows[0])
      res.json(users.rows[0]['username']!=null);
    else
      res.json(users)
      console.log(req.body)
    console.log(email,pass)
  } catch (err) {
    console.log(err.message);
  }
});

When I console.log the req.body it after running GetData

async function GetData() {

    const email = document.getElementById("email").value;
    const pass = document.getElementById("pass").value;
    const response = await axios.get("http://localhost:3002/login",
    {
      body: JSON.stringify({"email":  email, "pass" : pass})
    })
    console.log(response.config.body);
    console.log(response.data.rows)
  }

The body is said to be {} an empty object.

How do I send the body through axios the same way insomnia is sending a body.

When using insomnia and the exact same body it returns true as it should. enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

GET doesn’t accept sending a body, use POST instead:

router.post('/login', async function(req,res) {

// …

const response = await axios.post("http://localhost:3002/login", { email, pass })

Also, the response.config.body is not a thing, if you look at request config documentation, there is the property “data”, rather than “body”.

console.log(response.config.data);

Hopefully that helps!

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