Axios and Cookie Operation
My current service, response with the headers as follow:
Connection: keep-alive
Content-Language: en
Content-Length: 274
Content-Type: application/json; charset=utf-8
Date:
Server: Apache
Vary: Authorization, Accept-Language, Cookie
The Demo Header Service is as follow, the URL is http://httpbin.org/headers
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 528
Content-Type: application/json
Date:
Server: gunicorn/19.9.0
Via: 1.1 vegur
Some Keep Details about operations on Cookie from Axios
Some sample is as follow:
axios.request({
method: "get",
url: uri,
headers: headers,
params: params,
maxRedirects: 0,
validateStatus: function(status) {
return status >= 200 && status < 303;
},
withCredentials: true,
}).then(response => {
console.log("cookie:" + response.headers["set-cookie"]);
return resolve(response.data);
}).catch((error:any) => {
console.error(error);
return reject();
});
});
}
https://stackoverflow.com/questions/36365409/setting-cookies-with-cors-requests
On the server side, it should support these:
res.writeHead(200, {
’Set-Cookie’: ‘’,
‘Access-Control-Allow-Origin’: ‘http://sillycat.ddns.net:8383',
‘Access-Control-Allow-Credentials’: ’true’,
‘Access-Control-Allow-Methods’: ‘GET, POST’,
‘Access-Control-Allow-Headers’: ‘Content-Type, Set-Cookie, *'
});
In general, if the server side does not support CORS, the nodeJS client can not get the headers[’set-cookie’]. The browser can, postman can, but I fails to do that in NodeJS client without CORS.
References:
https://stackoverflow.com/questions/48846653/get-cookie-from-axios-response-using-cors-on-the-server-side
https://github.com/axios/axios/issues/92
https://github.com/axios/axios/issues/295
https://github.com/axios/axios/issues/953
https://stackoverflow.com/questions/48846653/get-cookie-from-axios-response-using-cors-on-the-server-side
My current service, response with the headers as follow:
Connection: keep-alive
Content-Language: en
Content-Length: 274
Content-Type: application/json; charset=utf-8
Date:
Server: Apache
Vary: Authorization, Accept-Language, Cookie
The Demo Header Service is as follow, the URL is http://httpbin.org/headers
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 528
Content-Type: application/json
Date:
Server: gunicorn/19.9.0
Via: 1.1 vegur
Some Keep Details about operations on Cookie from Axios
Some sample is as follow:
axios.request({
method: "get",
url: uri,
headers: headers,
params: params,
maxRedirects: 0,
validateStatus: function(status) {
return status >= 200 && status < 303;
},
withCredentials: true,
}).then(response => {
console.log("cookie:" + response.headers["set-cookie"]);
return resolve(response.data);
}).catch((error:any) => {
console.error(error);
return reject();
});
});
}
https://stackoverflow.com/questions/36365409/setting-cookies-with-cors-requests
On the server side, it should support these:
res.writeHead(200, {
’Set-Cookie’: ‘’,
‘Access-Control-Allow-Origin’: ‘http://sillycat.ddns.net:8383',
‘Access-Control-Allow-Credentials’: ’true’,
‘Access-Control-Allow-Methods’: ‘GET, POST’,
‘Access-Control-Allow-Headers’: ‘Content-Type, Set-Cookie, *'
});
In general, if the server side does not support CORS, the nodeJS client can not get the headers[’set-cookie’]. The browser can, postman can, but I fails to do that in NodeJS client without CORS.
References:
https://stackoverflow.com/questions/48846653/get-cookie-from-axios-response-using-cors-on-the-server-side
https://github.com/axios/axios/issues/92
https://github.com/axios/axios/issues/295
https://github.com/axios/axios/issues/953
https://stackoverflow.com/questions/48846653/get-cookie-from-axios-response-using-cors-on-the-server-side