我在节点 0.10 中有以下内容
var postData = querystring.stringify(data)
var options = {
host: 'localhost',
port: 80,
path: '/rest/messages/participant?format=json',
method: 'POST',
json: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
// console.log("body: " + chunk);
});
});
req.on('end', function(){
console.log('ended');
});
req.on("close", function(){
console.log("closed");
io.sockets.emit('added', data);
});
req.write(postData);
req.end();
'end'
事件和事件都不会'close'
被触发,即使http.request
像这样在对象中传递:
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
// console.log("body: " + chunk);
});
res.on("end",function(){ console.log("end");});
res.on("close",function(){ console.log("close");});
});
为什么我的事件没有触发?