node.js - nodejs request.post 无法获取cookies,但是request.get 是可以的。
问题描述
当我使用代码登录网站后。我想发送一个帖子请求,服务器无法获取 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();
谢谢!!!
解决方案
You can find cookie in:
res.headers['set-cookie']
and use it for next request.
推荐阅读
- asp.net-core - Asp.Net Core odata 无法识别控制器中的 Get 操作方法
- mongodb - Add total count to grouped + summed data
- c# - COMException (0x80041004): 没有足够的内存来操作 Crystal Reports
- mongodb - 无法使用 app.patch 并出现错误 发送到客户端后无法设置标头
- c# - 尝试排序时 DataGrid 数据消失
- r - 了解 ggpmisc 包 R 中 find_peaks 函数的忽略阈值参数
- r - 使用 R ggplot2 为图例键标签着色并删除键
- dart - 如何在 Dart 中比较相同的对象实例?
- asp.net-core - 带有通配符证书的 Kestrel HTTPS 端点
- c# - 实现模块化方法的最佳方法 - 反射