Var http = require (' http '); Var querystring = require (' QueryString ');// Request parameter Var postdata = querystring.stringify ({ ' name ': "Wangbin", ' password ': "123456", ' ServerID ': 2}); var options = { hostname: ' 192.168.1.135 ', port: 3001, path: '/ Login ', method: ' POST ', headers: { ' Content-Type ': ' application/x-www-form-urlencoded ', ' content-length ': postdata.length }};var req = http.request (Options, function (res) { res.setencoding (' UTF8 '); var resdata = []; res.on (' Data ', function (chunk) { resdata.push (chunk); }); res.on (' End ', function () { vaR data = resdata.join (""); console.log (data); }); Req.on (' Error ', function (e) { console.log (' problem with request: ' + e.message);}); / Send request Req.write (postdata); Req.end ();
This article is from the "Mirwangsir" blog, make sure to keep this source http://mirwangsir.blog.51cto.com/7723278/1695008
node. JS sends an HTTP request as a POST request