Node.js发送post请求的数据?

如何在Node.js环境中发送以下请求?

curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello World!' 

我试图与Nginx推送stream模块一起构build一个Node.js服务器。

您可能想要使用“请求”模块,我正在使用它,我感觉非常舒服。

扩展@Silviu Burcea对请求模块的建议:

 //Set up http server: function handler(req,res){ console.log(req.method+'@ '+req.url); res.writeHead(200); res.end(); }; require('http').createserver(handler).listen(3333); // Send post request to http server // curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello World!' // npm install request (https://github.com/mikeal/request) var request = require('request'); request( { uri:'http://localhost:3333/pub?id=my_channel_1', method:'POST', body:'Hello World!', }, function (error, response, body) { if (!error && response.statusCode == 200) { console.log('Success') } });