Created
June 20, 2020 09:58
-
-
Save fredriccliver/48e2050d7f7a3c7904430c54039d2f33 to your computer and use it in GitHub Desktop.
http request and read practice
This file contains hidden or 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 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