node.js - 为什么使用 axios 向不同域发送 GET 请求时未附加 cookie?
问题描述
我需要为 URL 中的部分域附加一个 cookie。为了测试这一点,我创建了两个在本地运行的域,分别为localdev1.test.com
和localdev2.test.com
. 在那里,我将 cookie 设置为.test.com
. 当我向同一个域发送一个简单的 get 请求时,它会附加 cookie,但在发送另一个域时,它不会附加 cookie。我给了{withCredentials:true}
。我为此使用了 reactJs 和 node。谁能建议我解决这个问题的方法?
const transport = axios.create({
withCredentials: true
});
transport
.get('http://localdev1.test.com:9000/api/messages/sample')
.then((res)=>{
alert(res.data.message);
})
.catch(err => { /* not hit since no 401 */ })
解决方案
推荐阅读
- node.js - 使用 Node.js 从 Redshift 将数据复制到 postgres
- python - Discord.py 谷歌图片搜索
- python - python计算器只加(if语句支配其他语句)
- java - 用 Mono 压缩 Flux 的正确方法是什么?
- google-cloud-platform - 缺少对“billingAccounts/XXXXXXXXXXXXXXXXXXXXXXXX”的权限:billing.resourceAssociations.create Terraform (GCP)
- python - 如何在 django 中读取所有带有特定前缀的图像?
- javascript - 如何在 JavaScript 中仅获取我的 json 对象值的直接父级?
- reactjs - Ag Grid - React- Datepicker 作为单元格编辑器不起作用
- python - 我无法使用 re 模块,我的解释器显示错误
- python-3.x - 树莓派和python实时