运行后能生成评论,但评论显示是乱码,求指教
var http = require('http'); var querystring = require('querystring'); var postData = querystring.stringify({ 'content':'老师讲得真好,这是追评!', 'cid':348, }); var options = { hostname:'www.imooc.com', port:80, path:'/course/docomment', method:'POST', headers:{ 'Accept':'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding':'gzip,deflate,sdch', 'Accept-Language':'zh-CN,zh;q=0.8', 'Connection':'keep-alive', 'Content-Length':postData.length, 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'Cookie':'imooc_uuid=bccbd401-fc48-47c0-8ac0-72fccc9681be; imooc_isnew_ct=1474427933; loginstate=1; apsid=gyYjE4MDEcd7b1393990c78efdeebff3968=1482889141', 'Host':'www.imooc.com', 'Origin':'http://www.imooc.com', 'Referer':'http://www.imooc.com/comment/348', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36', 'X-Requested-With':'XMLHttpRequest' } } 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(){ console.log('评论完毕!'); }); }); req.on('error',function(e){ console.log('Error: ' + e.message) ; }); req.write(postData); req.end();
运行后也没有执行console.log('评论完毕!')
求指教,谢谢!