为了账号安全,请及时绑定邮箱和手机立即绑定

我测试的时候返回状态吗为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':postData.length,
'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()


Status: 200

headers: {"server":"nginx","date":"Mon, 27 Jun 2016 12:23:24 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

评论完毕


正在回答

1 回答

1.methed拼写错误

2.post不能大写

测试成功!!!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
进击Node.js基础(一)
  • 参与学习       219315    人
  • 解答问题       982    个

本视频教程带你揭开Node.js的面纱,带你走进一个全新世界

进入课程

我测试的时候返回状态吗为200,但是刷新页面没有出来我通过程序注入的评论,是怎么回事呢

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号