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

338
Visualizações
Axios POST not working in Express app but same request works in Postman

So my express server is a middleman between a front-end app and an API that doesn't accept requests directly from the browser.

If I call the API from postman, I get a successful response. For context, heres the Postman code (in HTML view):

    POST hosted3.xyz.com/lookup\ HTTP/1.1
Content-Type: application/json
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
Accept-Encoding: gzip, deflate
Host: https://hosted3.xyz.com
Cache-Control: no-cache
Postman-Token: 72cdc54c-777f-e385-f6b8-5a3c5a8c0371

      {body...}

This works fine.

Now my express server is at localhost:4041 and its set up to make the same call as shown above, but this fails with a 500 Error: read ECONNRESET message.

Here is what that code looks like:

const express = require("express");
const bodyParser = require('body-parser');
const axios = require ('axios');
const xmlParser = require('fast-xml-parser');
const he = require('he');
const cors = require('cors')

const app = express();
const port = process.env.PORT || 4041;

app.use(cors())
app.options('*', cors());

app.post ('/querywrapper', (req, res, next) => {
  const headers = { 
      'Content-Type': 'application/json',
      'Accept': 'application/json, text/json, text/x-json, text/javascript, application/xml, text/xml',
      'Accept-Encoding': 'gzip, deflate',
      'Host': 'https://hosted3.xyz.com'
  };
  console.log (req.body);
 try {
   axios.post('https://hosted3.xyz.com/lookup/',  req.body, { headers })
  .then(response => {
      
     console.log ("recieved")
      console.log(JSON.stringify(response));
      res.json(response);
  })
      .catch(err => 
        next(err));
 }
 catch{         }
});

I'm testing this by running it and making the call (same body) from Postman. So I know it has nothing to do with my front end.

What am I doing wrong? And in with errors like these, what is the best way to debug?

Thanks!

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