为什么出现了404错误呢
var http =require('http');
var querystring=require('querystring');
var postData=querystring.stringify({
'content':'我是rm 测试成功',
'cid':8837
});
var options={
hostname:'www.imooc.com',
port:80,
path:'/course/documment',
method:'post',
headers:{
'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=2b72c77c-067a-49d1-b848-093b2eef5443; imooc_isnew_ct=1471439864; PHPSESSID=cb4plo5oggtrssaslhe01o0ot5; loginstate=1; apsid=k2YzhkNjJlMjE2NWYwMDU4ZDQ4MDRiMTFmZGUyOTkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzg0MzQ5NQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADNmNjUyODE2OWI0NjI2ZGIyMmMxZjQxYzRhMjdjOWQxNPN6WTTzelk%3DZT; IMCDNS=0;Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1500624538,1500627143,1501138099,1501229760; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1501231777; imooc_isnew=2; cvde=597af3024b3f6-45',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer':'http://www.imooc.com/video/8837',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
var req=http.request(options,function(res){
console.log('Status'+res.statusCode);
console.log(postData.length);
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);//请求头写进OPTIONS作为HTTP.REQUEST的第一个参数
//而请求体写进req.write方法内 且postData需要进行是序列化
req.end();