按照課程上面進(jìn)行測試,雖然評論成功了,但是沒有打印出?res.on('data',function(chunk){? ? ? ? console.log(Buffer.isBuffer(chunk));? ? ? ? console.log(typeof chunk);? ? });這個(gè)事件中的數(shù)據(jù),請問是什么原因呢?源代碼:var http =require('http');var querystring =require('querystring');var postData = querystring.stringify({? ? content:'不錯(cuò)不錯(cuò)不錯(cuò)',? ? 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();
nodejs http.request中的res.on沒有執(zhí)行
點(diǎn)點(diǎn)星光fighting
2017-05-18 16:38:31