【发布时间】:2021-09-11 23:59:26
【问题描述】:
在尝试从 React js 向 Python 烧瓶 API 发出 Axios API 调用时,我收到了 CORS 策略错误
Access to XMLHttpRequest at 'http://127.0.0.1:4000/testing' from origin 'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
任何人都可以指导我使用来自 react js 的以下 API 调用:
const headers = {
'Authorization': 'Bearer my-token',
'My-Custom-Header': 'foobar'
};
axios.post('http://127.0.0.1:5000/testing')
.then(console.log('OK'));
event.preventDefault();
由于我是 react js 新手,学习需要一些指导。
我尝试在项目的 package.json 文件中使用代理
【问题讨论】: