var https=require("https");
var querystring=require("querystring")
var postData=querystring.stringify({
'context':'测试数据最后一次!',
'cid':348,
'mid':8837,
})
var options={
protocol:'https:',
hostname:'www.imooc.com',
port:443,
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.9,en;q=0.8',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-length': postData.length,
'Cookie':'[]',
'Host': 'www.imooc.com',
'Pragma': 'no-cache',
'Referer': 'http://www.imooc.com/learn/348',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
}
var req=https.request(options,function (res) {
console.log(res.statusCode)
console.log(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();