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

返回200,评论失败,并且没有打印‘评论成功!’

var http = require('http')
var querystring =require('querystring')

var postData = querystring.stringify({
    'content': '努力学习nodejs,加油!',
    'mid':348
})

var options ={
    hostname: 'www.imooc.com',
    port:80,
    path:'/course/docomment',
    method:'POST',
    header:{
        '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=1d17e7b9-9df9-44a1-b5a7-4cf0a092f920; imooc_isnew_ct=1500877725; PHPSESSID=dcp8kto8lj2eqojjdi34o7prn5; loginstate=1; apsid=U0NDAzNGE2NDA4YjQ4MWFmYzk2Njc3YjMyOGNiODAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjMxMzY1MgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzOTAyODU2NzJAcXEuY29tAAAAAAAAAAAAAAAAAAAAAGYzZTYzZDAxNDI3NzM2ZWEzOTdlMjVhYWJjNmQxNDQ3BaGqWQWhqlk%3DMT; last_login_username=390285672%40qq.com; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1503813777,1503886846,1503910329,1504354539; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1504358510; imooc_isnew=2; cvde=59aaa0ef75730-50',
         'Host':'www.imooc.com',
         'Origin:http':'//www.imooc.com',
         'Referer:http':'//www.imooc.com/comment/348',
         'User-Agent':'Mozilla/5.0 (Windows NT 6.3; 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('header:'+ 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();


正在回答

1 回答

cmd返回这个:

Status:200

header:{"server":"nginx","date":"Sat, 02 Sep 2017 13:36:57 GMT","content-type":"

text/html; charset=utf-8","transfer-encoding":"chunked","connection":"close","va

ry":"Accept-Encoding, Accept-Encoding","set-cookie":["PHPSESSID=kj75nq5uqht856ap

r6ahhb00l6; path=/"],"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-cac

he"}

true

object


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

举报

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

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

进入课程

返回200,评论失败,并且没有打印‘评论成功!’

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

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

帮助反馈 APP下载

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

公众号

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