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

459
Visualizações
Nodejs PUT/PATCH is not working with axios and request but same works from Postman

I am trying to make some modifications to my Rest API by making the PUT request using request package but it does not seem to work so. Although I am able to make the modifications to the same API using the same JSON body using the Postman. Also, I am not getting any errors so not understanding what's wrong.

Since request was not working, I tried axios even with that no response no error. Following is my sample code which is making request to my Rest API:

const request = require('request');
const axios = require('axios');
const https = require('https');

request(
{ 
    url: testIdUrl,
    method: 'PUT',
    agentOptions: {
    rejectUnauthorized: false
  },
  headers: [{
    'content-type': 'application/json',
    body: JSON.stringify(requestBody)
  }]
},
function(error, response, body) {
  if(error){
    console.log("SOMETHING WENT WRONG")
    console.log(error)
  }
  console.log("RESPONSE FROM TEST ID PUT")
})   

axios.put(testIdUrl, requestBody)
.then((res) => {
    console.log(`Status: ${res.status}`);
    console.log('Body: ', res.data);
}).catch((err) => {
    console.error(err);
}); 

Can someone please help me understand what's wrong with the code? Does my Rest API include all the tokens and information? When I use the same requestBody and URL then its works in POSTMAN.

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