//慕课网发表评论
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',
'Accept-Language' : 'zh-CN,zh;q=0.8,en;q=0.6',
'Connection' : 'keep-alive',
'Content-Length' : postData.length,
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie' : 'imooc_uuid=95342067-bbfd-4abd-8cc1-db9e874110fc; imooc_isnew_ct=1494672031; UM_distinctid=15c4c87a804366-0c7c49946c1b24-3e64430f-1fa400-15c4c87a80559e; CNZZDATA1261110065=408120519-1495928926-null%7C1495928926; loginstate=1; apsid=E4MGNkY2ZmZGU4ZjYyM2ZhNWNmYzhlMjk0MDIyZDMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTg4MTc4NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxNjQ3Mzk4NTc0QHFxLmNvbQAAAAAAAAAAAAAAAAAAADQ2MmI2NzJjY2I0OWFhMjdlYzc5ZmQ5ZWNiMDFkMmY4bqRcWW6kXFk%3DMj; last_login_username=1647398574%40qq.com; PHPSESSID=mv3om14aiq1idedsd1u7gm3eo1; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1498049228,1499243562,1499394973; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1499499119; imooc_isnew=2; cvde=595ef3aa3bab7-155',
'Host' : 'www.imooc.com',
'Origin' : 'http://www.imooc.com',
'Referer' : 'http://www.imooc.com/video/8837',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
'X-Requested-With' : 'XMLHttpRequest',
}
}
var req = http.request(options, function(res) {
console.log(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('评论成功');
});
res.on('error', function(e) {
console.log(e.message);
});
});
req.write(postData);
req.end();