我测试的时候返回状态吗为200,但是刷新页面没有出来我通过程序注入的评论,是怎么回事呢
这是我的代码,麻烦帮帮看看
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',
metod:'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,zh-TW;q=0.4,ja;q=0.2,sq;q=0.2',
'Connection':'keep-alive',
'Content-Length':97,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'/复制的cookie不会有错/',
'Host':'www.imooc.com',
'Origin':'http://www.imooc.com',
'Referer':'http://www.imooc.com/comment/348',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
console.log(postData.length);
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 (e){
console.log('评论完毕');
})
})
req.on('error',function(e){
console.log('errors:'+e.message)
})
req.write(postData)
req.end()