var http = require('http');
var querystring = require('querystring');
var postData = querystring.stringify({
'content':'咳咳,嗯,测试一下,谢谢!',
'mid':8837
});
var options = {
hostname:'www.imooc.com',
port:80,
path:'/course/document',
method:'POST',
headers:{
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Charset':'GBK,utf-8;q=0.7,*;q=0.3',
'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=cebeebe6-0311-4855-9928-56d866a61b1b; imooc_isnew_ct=1464523511; loginstate=1; apsid=RkYTQwYjQ2MzE1Y2YwZWUwNTMzZGEwOTQzODIyYzUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAMzgwMDYyMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4NDI1MjgyMDlAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGQwMD' +
'czOGE5MGRlMTdlNTEwMTQ3ZDZiY2IxYmM5ODY19vTUV%2Fb01Fc%3DYW; last_login_username=842528209%40qq.com; PHPSESSID=gk6j6fgqf4bsv0vomqv45rdlt6; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1474607835,1474607850,1474608573,1474608607; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1474615638; jwplayer.volume=26; imooc_isnew=2; cvde=57e47dfa78b39-41',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer':'http://www.imooc.com/video/8837',
'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
'X-Requested-With':'XMLHttpRequest'
}
};
var req = http.request(options, function (res) {
console.log('status:'+res.statusCode);
console.log('headers'+JSON.stringify(res.headers));
//接收的数据是以流的形式传来,会触发on事件
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();