AWS Elastic Beanstalk上的Axios CORS问题



我在aws Elastic Beanstalk上有一个fastapi主机。我想建立一个vue应用程序与之交互。

但是,当我尝试时

const res = await axios.post(baseUrl, 
{
HMA_lat: 22.33012,
HMA_Lng: 114.1641913,
blg_age: 19
},
{
headers:{
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
}
}
)

在浏览器控制台中,我得到了CORS错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://..... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

我应该修改Elastic Beanstalk服务器中的seeting吗?如果是,我该怎么做?

您可以在本地系统上通过将Allow Control Allow Origin添加到chrome浏览器并在其中添加本地主机来解决此问题。还有一个类似的问题可能会对您有所帮助。

我需要在FastAPI 中添加CORS(跨源资源共享(中间件

参考:https://fastapi.tiangolo.com/tutorial/cors/

最新更新