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

603
Vistas
NodeJS Error when sending POST request using http.request or Axios

I'm trying to send some data in NodeJS from one localhost server to another, but I'm getting a nasty error. On the server that receives the request it appears the request goes through because I'm getting an object logged to the terminal there, except its properties are null (they're supposed to be set to the properties in the req body, or null).

I get the error even if I try with Axios, which tells me that it’s not an issue with http.request or Axios. If anyone could help me understand what's going on I'd appreciate it.

Error:

    events.js:377
          throw er; // Unhandled 'error' event
          ^
    
    Error: write EPROTO 8669511168:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
    
        at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16)
    Emitted 'error' event on ClientRequest instance 
    {
      errno: -100,
      code: 'EPROTO',
      syscall: 'write'
    }

The project sending the request looks like this:

Resources file

    const http = require('http');
    const options = {
        host: 'localhost',
        port: 3000,
        path: '/create',
        method: 'POST',
        header: {
            'Content-Type':'application/json'
        }
    }

    const body = {
        inquiryTotal: ‘20.00’
    }
    const stringifiedBody = JSON.stringify(body)
    
    module.exports.Inquiries = {
        create: () => {
            req = http.request(options, (res) => {
                console.log(res);
            });
            req.write(stringifiedBody); // this is an object that's already stringified to JSON
            req.end();

            /*axios.post('localhost:3000/v1/orders/create', {
            orderTotal: '21.00'
        }).then(res => {
            console.log(res);
        }).catch(err => {
            console.log(err);
        })*/
        }
    }

Server sending request:

    const resource = require('./lib/resource');
    // create server code
    resource.Inquiries.create;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming you are correctly setup your API endpoint, you can try this (added some comments inside the code):

const axios = require("axios").default;

const body = {
  inquiryTotal: "20.00" // Use single-qupte ('') or double-quote ("") here and don't use back-quote (``)
};

module.exports.Inquiries = {
  create: () => {
    axios
      .post("http://localhost:3000/v1/orders/create", body) // Add http:// in the beginning of your url
      .then((res) => {
        console.log(res);
      })
      .catch((err) => {
        console.log(err);
      });
  }
};
about 4 years ago · Juan Pablo Isaza Denunciar
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