J
J
jtag2018-02-10 18:30:43
Node.js
jtag, 2018-02-10 18:30:43

How to send json over http?

There are two servers, how to send a request from the second server to the first server:

const http = require('http');
    http.createServer((req, res)=>{
      
    }).listen(1337);

const http = require("http");
const request = http.request({
    'host': 'localhost',
    'port': 1337,
    'path': '/',
    'method': 'POST'
});

request.on('response', function (res) {
    res.on('data', function(data){
        console.log(data);
    });
})
request.end();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-02-10
@yellow79

request.write(JSON.stringify({hello:"world"}));
request.end();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question