var http = require('http')
var querystring =require('querystring')
var postData = querystring.stringify({
'content': '努力学习nodejs,加油!',
'mid':348
})
var options ={
hostname: 'www.imooc.com',
port:80,
path:'/course/docomment',
method:'POST',
header:{
'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=1d17e7b9-9df9-44a1-b5a7-4cf0a092f920; imooc_isnew_ct=1500877725; PHPSESSID=dcp8kto8lj2eqojjdi34o7prn5; loginstate=1; apsid=U0NDAzNGE2NDA4YjQ4MWFmYzk2Njc3YjMyOGNiODAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjMxMzY1MgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzOTAyODU2NzJAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGYzZTYzZDAxNDI3NzM2ZWEzOTdlMjVhYWJjNmQxNDQ3BaGqWQWhqlk%3DMT; last_login_username=390285672%40qq.com; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1503813777,1503886846,1503910329,1504354539; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1504358510; imooc_isnew=2; cvde=59aaa0ef75730-50',
'Host':'www.imooc.com',
'Origin:http':'//www.imooc.com',
'Referer:http':'//www.imooc.com/comment/348',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
var req = http.request(options,function(res){
console.log('Status:'+ res.statusCode)
console.log('header:'+ 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();