nodejs基础一request命令 提交评论 为啥我显示403但是后面还是能够成功啊 老师

来源:

代小代

2016-09-01

$ node request.js

Status: 403

headers: {"server":"Beaver","cache-control":"no-cache","content-type":"text/html","content-length":"594","connection":"close"}

true

object

评论成功




var http=require('http')

var querystring=require('querystring');

var contentData = {

    'content':'努力天天向上',

    'mid':8837

};

var pataData=querystring.stringify(contentData);


var options={

hostname:'www.immooc.com',

port:'80',

path:'/course/docomment',

method:'POST',

headers:{

'Accept':'application/json, text/javascript, */*; q=0.01',

        'Accept-Encoding':'gzip, deflate',

        'Accept-Language':'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4',

        'Connection':'keep-alive',

        'Content-Length':pataData.length,

        'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',

        'Cookie':'imooc_uuid=76e16dc8-6893-46f6-a732-8a287d536c3c; imooc_isnew_ct=1468987904; loginstate=1; apsid=kwNWQwYTI5ZGMyYjliMzdlNjBlMDNkYjdmNmYwZTIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzU0MzU5OAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1MDE4OTQxODhAcXEuY29tAAAAAAAAAAAAAAAAAAAAADNmYzc4YzgyMzI3NjM3YTQ5YjE5NDYzNzk1ZGU0YTQ4UaOmV1Gjplc%3DMj; last_login_username=501894188%40qq.com; bdshare_firstime=1471354375168; PHPSESSID=h396rj39qrggq61tr37qfejkj1; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1471961948,1472012268,1472031648,1472651040; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1472731819; imooc_isnew=2; cvde=57c6df1ab5074-117',

        'Host':'www.imooc.com',

        'Origin':'http://www.imooc.com',

        'Referer':'http://www.imooc.com/video/8837',

        'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36',

        '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))//判断是否是buffer类型

      console.log(typeof chunk);

     })

     res.on('end',function(){

      console.log('评论成功');

     })

})

     req.on('error',function(e){

       console.log('Error: '+e.message)

    })

    req.write(pataData)

    req.end()


写回答

1回答

代小代

提问者

2016-09-01

但是评论区木有内容的提交

0
0

7天搞定Node.js微信公众号

Koa框架、ES2015新特性、MongoDB,开发微信公众号

1742 学习 · 787 问题

查看课程