Const HTTP = require (' http '); Const QueryString= Require (' querystring '); Const PostData=querystring.stringify ({' msg ': ' Hello world! -----Hallelujah '}); const options={hostname:' 192.168.1.6 ', Port:8080, Path:'/hello ', Method:' POST ', headers: {' Content-type ': ' application/x-www-form-urlencoded ', ' Content-length ': Buffer.bytelength (PostData)}}; Const REQ= Http.request (options, (res) = ={console.log (' STATUS: ${res.statuscode} '); Console.log (' HEADERS: ${json.stringify (res.headers)} '); Res.setencoding (' UTF8 '); Res.on (' Data ', (chunk) ={console.log (' BODY: ${chunk} '); }); Res.on (' End ', () ={Console.log (' No more data in response. '); });}); Req.on (' Error ', (e) = ={console.error (' problem withrequest: ${e.message} ') ;//write data to request bodyReq.write (postdata); Req.end ();
Nodejs POST Request