var https = require('https')
var querystring = require('querystring')
var postData = querystring.stringify({
    'content': 'test....',
    'mid': 8837,
    'r': 0.8931310037811482
})
var options = {
	hostname:'www.imooc.com',
	port:443,//http默认端口80,https默认端口443
	path:'/course/docomment',
	method:'POST',
	headers:{//request headers
        'Accept':'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding':'gzip, deflate, br',
        'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8',
        'Cache-Control':'no-cache',
        'Connection':'keep-alive',
        'Content-Length': postData.length,
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Cookie':'....',
        'Host':'www.imooc.com',
        'Pragma':'no-cache',
        'Referer':'https://www.imooc.com/video/8837',
        'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36',
        'X-Requested-With':'XMLHttpRequest'
    }
}
var req = https.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();