【发布时间】:2020-06-24 14:51:08
【问题描述】:
我正在尝试从 api 访问数据,但出现此错误
从源“http://localhost:3000”访问“http://example.com/api/login”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“访问控制允许源” ' 请求的资源上存在标头。
这是我的代码
return axios.post('http://example.com/api/login', { username: username, password: password }).then(response => {
console.log('response', response);
if (response.status === 400 || response.status === 500)
throw response.data;
return response.data;
}).catch(err => {
console.log('err', err);
throw err[1];
});
使用 asp.net 构建的后端
谢谢
【问题讨论】: