我想用node js模拟一个登录。该请求是post请求,并且返回302。
当我想在节点中用一个请求来模拟它时,我得到了错误:
Unhandled rejection StatusCodeError: 302 但当我查看google chrome时,它的响应是空的,但有一个Cookie响应。如何通过节点请求获取此cookie?

发布于 2018-07-24 18:06:36
下面是获取cookies的示例代码:
$.ajax({
type: "POST",
url: AppConstants.URLs.PROXY,
data: message,
xhrFields: {
withCredentials: true
},
success: function(data, status, xhr) {
console.log("Cookie: " + xhr.getResponseHeader("Set-Cookie"));
}
});您可以使用从node.js的服务器端设置cookies
如何通过节点请求获取此cookie?
var jsdom = require('jsdom');
var window = jsdom.jsdom().parentWindow;
var Cookies = require('cookies-js')(window);
// First set a cookie
Cookies.set('key', 'value');
// Get the cookie value
Cookies.get('key'); // "value"
// Using the alias
Cookies('key'); // "value"希望这能有所帮助。
https://stackoverflow.com/questions/51495690
复制相似问题