• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

为啥status:302

/****代码部分****/
var http = require('http');
var querystring = require('querystring');


var postData = querystring.stringify({
        'content': '再接再厉,更加努力的好好学习天天向上',
        'cid': 709
})


var options = {
        hostname: 'www.tianmg.com',
        port: 80,
        path: '/course/docoment',
        method: 'POST',
        headers: {
                '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':'tianmg_uuid=70242a20-5712-451c-ac97-ebdf6f371be8; tianmg_isnew_ct=1451440514; loginstate=1; apsid=ZkZDk1OTMxOGUxNTBkNWRhYzczY2ZhNGJiY2ZhZjcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTAxMDM4MQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5NTczMTQ3MjRAcXEuY29tAAAAAAAAAAAAAAAAAAAAADcxZDJhMDc3ZTU2YWFlZDM0MmE5Y2JhYjFmMDQ1ZGYyGY%2FGVxmPxlc%3DN2; last_login_username=957314724%40qq.com; PHPSESSID=hul9p17hrro2erllb8c43e1j45; tianmg_isnew=2; cvde=57c8d5ee44321-4; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1472630492,1472779758; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1472779779',
                'Host':'www.tianmg.com',
                'Origin':'http://www.tianmg.com',
                'Referer':'http://www.tianmg.com/comment/709',
                'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 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));
                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();
/****控制台部分****/
D:\nodejs\node-1\scott\tianmg\beginning>node comment.js
Status:302
headers:{"server":"nginx","date":"Fri, 02 Sep 2016 02:03:07 GMT","content-type":
"text/html","transfer-encoding":"chunked","connection":"keep-alive","expires":"T
hu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalida
te, post-check=0, pre-check=0","pragma":"no-cache","location":"/error/noexists"}


评论完毕!




求高手指导

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与2

谢谢大侠的回答,那请问出现这个问题的话,我怎么还能把这个例子成功的实现。就是在302的状态下怎么能通过node成功发出post请求

使用道具 举报

获开的状态码是什么取决于服务器返回的内容, 状态码也是HTTP响应头的一项内容 , 302表示页面重定向

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!