var options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
//You do not have to write this listener if you don't want to
//but NOde will still get all the chunks of data, and attempt to
//call a callback it will find null, and end up discarding every "chunk"
});
res.resume();//Omitting the above(empty ondata listener) and including this line, would exhibit almost identical behavior, res.resume() being very slightly more performant.
//Not there is no res.end(), even in the version that is processing data
//Calling end() is the job of the sender, not the receiver
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
//req.end() signifies the end of the data that you are writing to the
//responding computer.
http://www.infoq.com/news/2013/01/new-streaming-api-node
请参阅上面的链接以获取信息作为参考,了解为什么现在需要这样做。