
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':'en-US,en;q=0.8,xh-CN;q=0.6,zh;q=0.4',
'Cache-Control':'no-cache',
'Connection':'keep-alive',
'Content-Length':postData.length,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'imooc_uuid=3b1abdc4-3362-42b2-b668-1cf0561917da; imooc_isnew_ct=1496715442; PHPSESSID=oi6sr43s3eom2s11iaalifs9e0; loginstate=1; apsid=c1ZTRhYjQ3NDI0MTUxNTkxNDhjNTJkNjRjZmQwN2MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjQ2Nzk2NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMTUyNTA3NjIyQHFxLmNvbQAAAAAAAAAAAAAAAAAAADRmNjU1YjRjNDIzNGIyZDM2NTRiNWQ4NzE5YjVlZGNk5p83WeafN1k%3DMz; last_login_username=1152507622%40qq.com; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1496715472,1496815996; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1496817699; imooc_isnew=2; cvde=5937997f27536-41',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer:http':'//www.imooc.com/comment/348',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
var req = http.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('评论完毕')
})
res.on('error',function(e) {
console.log('Error: '+ e.message)
})
req.write(postData)
req.end()
})