Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created June 20, 2020 09:58
Show Gist options
  • Save fredriccliver/48e2050d7f7a3c7904430c54039d2f33 to your computer and use it in GitHub Desktop.
Save fredriccliver/48e2050d7f7a3c7904430c54039d2f33 to your computer and use it in GitHub Desktop.
http request and read practice
const http = require('http')
const theRequest = http.request({
host: 'localhost',
path: '/',
port: 3000,
method: 'POST',
headers: {
'message': "this is a message included in the header"
},
body: JSON.stringify({
"message": "this is located in body in option"
})
}, function (res) {
var str = '';
res.on('data', function (chunk) {
str += chunk;
});
res.on('end', function () {});
})
theRequest.on('error', (err) => {
console.log("request error occured")
console.log(err)
})
theRequest.write(
JSON.stringify({
message: "this is located in write"
})
)
theRequest.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment