请问结果为404?? //运行结果如下,页面刷新并无评论结果
var http=require('http');
var querystring=require('querystring');
var postData=querystring.stringify({'content':'准备进军vue.js',
'mid':'12300'});
var options={
hostname:'www.imooc.com',
port:80,
path:'/cource/docomment',
method:'POST',
headers:{
'Accept':'application/json, text/javascript, */*; q=0.01',
'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=3ed8e016-847d-4f28-a994-9438581e4d6b; imooc_isnew_ct=1492234750; loginstate=1; apsid=Q2OTQ5NDJlM2MyNzcyOGIxMGVjN2VjNjVmNWU5ZjUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTA0ODMzMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5OTUxODY4OTFAcXEuY29tAAAAAAAAAAAAAAAAAAAAADZkYWZkMDM4ZDE3ZDRlYWRkYWRhYmE4ZDU0YjAxZDNjPMbyWDzG8lg%3DYT; last_login_username=995186891%40qq.com; PHPSESSID=vbaei1taf76podt1csfpv2vio3; mc_channel=banner; mc_marking=18dd20a2a135892a038a3edb06684f99; cninfo=banner-18dd20a2a135892a038a3edb06684f99; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1492234971,1492305397,1493029533,1493164662; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1493215968; imooc_isnew=2; cvde=58ffe2717d8c8-246',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer':'http://www.imooc.com/video/12300',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0',
'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('comment completed!!');
});
res.on('error',function(e){
console.log('Error:'+e.message);
})
});
req.write(postData);
req.end();
//问题:结果404,为什么??
//运行结果如下,页面刷新无评论结果
E:\node\http>node comment.js
Status:404
headers:{"server":"nginx","date":"Wed, 26 Apr 2017 14:31:19 GMT","content-type":"text/html; charset=utf-8","transfer-encoding":"chunked","connection":"keep-alive","vary":"Accept-Encoding, Accept-Encoding","expires":"Thu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0","pragma":"no-cache","content-encoding":"gzip"}
true
object
comment completed!!