求解求解求解啊
var http = require('http');
var querystring = require('querystring');
var postData = querystring.stringify({
? ?content: '測試,老師講的不錯',
? ?mid: 8837
});
var options = {
? ?hostname: 'idcbgp.cn',
? ?port: 80,
? ?path: '/course/docomment',
? ?method: 'POST',
? ?headers: {
? ? ? ?'Accept': 'application/json, text/javascript, */*; q=0.01',
? ? ? ?'Accept-Encoding': 'gzip, deflate',
? ? ? ?'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=a7c31528-7bed-45e9-95a3-5bfbe4a6b6ab; imooc_isnew_ct=1492094814;loginstate=1;apsid=Q4ODQ5NTJmODc2MjczNzI4OWNlNjk1MGJkMTAwNzcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANTE4OTYxMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyMDI1NTA2MjgyQHFxLmNvbQAAAAAAAAAAAAAAAAAAADIyNjI0NWU3ZGI5NzQ0Yzg1MmY0NzdiNDRhMzBjY2JkIF3wWCBd8Fg%3DYz;last_login_username=2025506282%40qq.com; bdshare_firstime=1492502681751;PHPSESSID=v0uortc2dg9fdmg1pi1n7e7bs2;Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1492605759,1492671530,1492692810,1492761448;Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1492761463; imooc_isnew=2; cvde=58f9bb784c83a-15',
? ? ? ?'Host': 'idcbgp.cn',
? ? ? ?'Origin': 'http://idcbgp.cn',
? ? ? ?'Referer': 'http://idcbgp.cn/video/8837',
? ? ? ?'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36(KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36',
? ? ? ?'X-Requested-With': 'XMLHttpRequest'
? ?}
};
var req = http.request(options, function (res) {
? ?console.log(res.STATUS_CODES);
? ?console.log(JSON.stringify(res.headers));
? ?res.on('data', function (chunk) {
? ? ? ?console.log(Buffer.isBuffer(chunk));
? ? ? ?console.log(typeof chunk);
? ?});
? ?res.on('end', function (chunk) {
? ? ? ?console.log('評論完畢');
? ?});
? ?req.on('error', function (e) {
? ? ? ?console.log('request is wrong');
? ? ? ?console.log(e.message);
? ?});
? ?req.write(postData);
? ?req.end();
});
2017-04-27
還有res.statusCode,不是res.STATUS_CODES
2017-04-27
你后面括號 擴錯了
var?req?=?http.request(options,?function?(res)?{ ???console.log(res.STATUS_CODES); ???console.log(JSON.stringify(res.headers)); ???res.on('data',?function?(chunk)?{ ???????console.log(Buffer.isBuffer(chunk)); ???????console.log(typeof?chunk); ???}); ???res.on('end',?function?(chunk)?{ ???????console.log('評論完畢'); ???}); ?}); ?req.on('error',?function?(e)?{ ?????console.log('request?is?wrong'); ?????console.log(e.message); ?}); ?req.write(postData); ?req.end();我已經(jīng)用你的號評論了……