首页 > 解决方案 > 为什么使用 axios 向不同域发送 GET 请求时未附加 cookie?

问题描述

我需要为 URL 中的部分域附加一个 cookie。为了测试这一点,我创建了两个在本地运行的域,分别为localdev1.test.comlocaldev2.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.jsreactjsaxios

解决方案


推荐阅读