【问题标题】:nodejs request.post be unable to get the cookies , but request.get is can 。nodejs request.post 无法获取cookies,但是request.get 是可以的。
【发布时间】:2018-08-20 11:51:43
【问题描述】:

当我使用代码登录网站后。我想发送一个 post 请求,服务器无法获取 cookie,但获取请求是可以的。

我的代码:

var req = require('request');
req.defaults({ jar: true });

 const loginUrl = 'https://www.a.com/auth/login';
 const scoreUrl = 'https://app-test.a.com/bms/CustomerAccount/member/get-list-task?_ac=OperationCenter&_smp=OperationCenter.Member';

function login(options, cb) {

req.post({
    url: loginUrl,
    form: {
        'tenantCode': 'jfdc',
        'userName': 'jfdc',
        'password': 'sh123456'
    }
},
    function (err, res, body) {
        var cb = function (err, res, body) {
            console.log(body);
        };

        options = {
            url: scoreUrl,
            data: {
                page: 1,
                pageSize: 10,
                corp_id: '11b11db4-e907-4f1f-8835-b9daab6e1f23',
                key: '111111111111111',
                sort_list: [],
                _t: 1534647594968
            }
        };
        req.post(options, cb);
    });
}

login();

谢谢!!!

【问题讨论】:

    标签: node.js post cookies request


    【解决方案1】:

    您可以在以下位置找到 cookie:

    res.headers['set-cookie']
    

    并将其用于下一个请求。

    【讨论】:

    • 是的,我可以得到cookie。但是在'app-test.a.com'的request.header中检查cookie。
    猜你喜欢
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2013-12-21
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多