http.request请求中的data怎么打印?
var http = require('http')
var $ = require('jquery')
var url = require('url')
var BufferHelper = require('bufferhelper');
var options = {
hostname:'ask.39.net',
path:'/',
method:'GET',
headers:{
'Accept':'*/*',
'Connection':'close',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31'
}
}
var bufferHelper = new BufferHelper();
var req = http.request(options,function(res){
res.on('data', function (chunk) {
bufferHelper.concat(chunk)
});
})
req.end()
console.log(bufferHelper.toBuffer().toString())**strong text**
上面的data一直无法正常打印出来了。求修改代码
3 回复
console.log怎么写在了end()的外面?貌似典型的同步编程思维
OK,增加了res.on(‘end’)事件就打印出来了。。