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

601
Visualizações
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 Respostas
Responde à pergunta

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