javascript - 我设置withCredentials为真,但是Axios中跨站请求失败
问题描述
跨站 url 是可以直接访问的,但我不能通过跨站请求将 cookie 发送到另一个页面。
代码
export const UserLogin = data => {
return dispatch => {
dispatch({ type: USER_LOADING, data: true });
axios
.post(`${config.apiPath}/api/user/login`, data, { withCredentials: true })
.then(function(response) {
localStorage.setItem("user_agency_mgmt", JSON.stringify(response));
dispatch({ type: USER_LOADING, data: false });
return dispatch({ type: USER_LOGIN, data: response });
})
.catch(function(xhr, status, err) {
dispatch({ type: USER_LOADING, data: false });
return dispatch({ type: USER_LOGIN_FAILURE, error: xhr });
});
};
};
配置文件
常量 env = process.env.NODE_ENV || “发展”;
const config = {
development: {
apiPath: "https://api.realtor.agency21.rocks",
domain: "localhost",
revivePath: "https://revive.graana.rocks",
lockScreen: true
},
production: {
apiPath: "https://api.realtor.agency21.rocks",
domain: ".agency21.rocks",
revivePath: "https://revive.graana.rocks",
lockScreen: true
},
domain: ".agency21.rocks"
};
module.exports = config[env];
注意:当我更改apiPath
它http://localhost:3001
时工作正常但是当我更改https://api.realtor.agency21.rocks
cookie 的路径时在跨站点上不起作用
解决方案
推荐阅读
- c++ - 无法实现队列
> 在 C++ 中 - html - 子组件向父组件发出的事件的奇怪行为
- node.js - 使用全局配置扩展模块而不破坏当前使用
- linux - Trying to assemble an IA32 assembly file and getting operand mismatch error for 'call'
- python-3.x - For 循环仅输出列表中最后一项的 API 数据
- sql - 如何在没有聚合函数 SQLPLUS Oracle11g 的情况下查找具有最大值的行
- javascript - 我想将一个标记移动到另一个
- android - 如何从 android 项目中的 gradle 依赖项中排除 Jar 文件
- php - 为什么我有 eclipse 错误,这段代码是有效的还是 eclipse 错误?
- javascript - 如何在javascript中模拟数组?