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

339
Vistas
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 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