Created
March 26, 2019 04:45
-
-
Save marciopuga/1b0ab6701cfc7f6a1574a92a3c634f5b to your computer and use it in GitHub Desktop.
Send POST request using Vanilla Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const options = { | |
hostname: 'localhost', | |
port: 3000, | |
path: '/path', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
} | |
var req = http.request(options, function (res) { | |
res.setEncoding('utf8') | |
res.on('data', function (body) { | |
console.log('Body: ' + body) | |
}) | |
}) | |
req.on('error', function (e) { | |
console.log('problem with request: ' + e.message) | |
}) | |
const data = {hello: "world"} | |
req.write(JSON.stringify(o)) | |
req.end() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment