【发布时间】:2020-01-01 05:15:35
【问题描述】:
我正在尝试从本地主机调用 mixpanel jql api 并遇到了 CORS 问题。
这是我的电话:
try {
const res = await axios({
method: "post",
url: "https://mixpanel.com/api/2.0/jql",
data,
withCredentials: true,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Access-Control-Allow-Credentials": 'true',
"Access-Control-Allow-Origin": "*",
},
auth: {
username: xxxxxxxxxxx,
}
});
console.log(res.data);
} catch(error) {
console.log(error);
}
这是浏览器中的错误:
从源“http://localhost:3000”访问“https://mixpanel.com/api/2.0/jql”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:“Access-Control-Allow-Credentials”的值' 响应中的标头为 '',当请求的凭据模式为 'include' 时,它必须为 'true'。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。
任何帮助将不胜感激。
【问题讨论】: