Axios and Cookie Operation

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值