var http = require('http');
var querystring = require('querystring');
var aData={
'content':'为什么中文无法正常提交',
'mid':8837
};
var postData = querystring.stringify(aData);
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':'zh-CN,zh;q=0.8,en;q=0.6',
'Cache-Control':'no-cache',
'Connection':'keep-alive',
'Content-Length':postData.length,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'PHPSESSID=ijvlq7nepvf8rr9es038ki3mo1; imooc_uuid=679effa9-6f99-4b2f-8114-40626657fdd2; imooc_isnew_ct=1485434944; loginstate=1; apsid=Y1ZTUwNmRlY2YwNmMzYmE4OGM3YTlmYTg5ZDdkZTkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTM1MTQyMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1NDMxMDkxNDBAcXEuY29tAAAAAAAAAAAAAAAAAAAAADA5MzE2MGU2M2I3YmFmY2VmNTczN2E4OTc5YzNjYjEyobeMWKG3jFg%3DZT; last_login_username=543109140%40qq.com; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1485607650,1485657096,1486294548,1486734444; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1486979933; imooc_isnew=2; cvde=5889f040ec42e-1221',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Pragma':'no-cache',
'Referer':'http://www.imooc.com/video/8837',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; 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('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();