按照课程上面进行测试,虽然评论成功了,但是没有打印出 res.on('data',function(chunk){ console.log(Buffer.isBuffer(chunk)); console.log(typeof chunk); });这个事件中的数据,请问是什么原因呢?源代码:var http =require('http');var querystring =require('querystring');var postData = querystring.stringify({ content:'不错不错不错', cross_post:1, belongId:2862414});var options ={ hostname: 'v.yinyuetai.com', port:80, path:'/video/2862414', method:'POST', headers:{ 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8', 'Cache-Control':'max-age=0', 'Connection':'keep-alive', 'Content-Length':postData.length, 'Content-Type':'application/x-www-form-urlencoded', 'Host':'comment.yinyuetai.com', 'Origin':'http://v.yinyuetai.com', 'Referer':'http://v.yinyuetai.com/video/2862414', 'Upgrade-Insecure-Requests':1, 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' }}var req =http.request(options,function(res){ console.log('status: '+res.statusCode); console.log('headers: '+JSON.stringify(res.headers)); res.on('data',function(chunk){ console.log(Buffer.isBuffer(chunk)); console.log(typeof chunk); }); res.on('end',function(e){ console.log('评论完毕!'); })});req.on('error',function(e){ console.log('Error: '+e.message);});req.write(postData);req.end();
添加回答
举报
0/150
提交
取消