I want to simulate a login with node js. The request is a post request and returns 302.
When i want to simulate it with a request in node i get error:
Unhandled rejection StatusCodeError: 302
But when i look at google chrome the response is empty but there is a Cookie Response. How can i get this cookie with a node request?
Here is sample code for getting 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"));
}
});
You can set cookies from server side at node.js using Cookies-js
How can i get this cookie with a node request?
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"
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.