request
is now deprecated. It is recommended you use an alternative
In no particular order and dreadfully incomplete:
Stats comparision
Some code examples
Original answer:
This gets a lot easier if you use the request library.
var request = require('request');
request.post(
'http://www.yoursite.com/formpage',
{ json: { key: 'value' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
Aside from providing a nice syntax it makes json requests easy, handles oauth signing (for twitter, etc.), can do multi-part forms (e.g. for uploading files) and streaming.
To install request use command npm install request
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…