azure - 无法在 Azure Functions Linux 消费计划上编辑 CORS
问题描述
我已经在 Python 中实现了一个 Azure 函数,它只适用于 Azure Linux 服务器。使用 Visual Studio Code 我设法在本地运行这些函数并使用邮递员执行测试,请求成功运行。我还使用 Visual Studio Code 将这些功能部署到 Azure,并再次使用 Postman 测试了公共 REST API 主机并且它工作正常。
问题是通过我的 Web 应用程序调用这个 API,它返回了 CORS 错误。我知道这是正常的,因为我没有通过 Azure 面板在 CORS 中设置允许所有 (*) 属性。基本上,因为 CORS 被阻止:
当我单击时,我收到以下警告:
This feature is not supported for Linux apps on a Consumption plan
我尝试在我的 python 函数中添加标题,例如:
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS"
}
然后在响应中:
return func.HttpResponse(f"{result}",headers=headers)
但仍然收到 CORS 错误。
解决方案
尝试使用Azure CLI启用 CORS ,
az functionapp cors add --allowed-origins
[--ids]
[--name]
[--resource-group]
[--slot]
[--subscription]
推荐阅读
- php - 是否可以在存储过程参数中传递多个输入值?
- excel - 使用 VBA 从雅虎财务中检索数据(资产负债表而不是股票)
- assembly - 具体的汇编命令函数
- javascript - 如何在赛普拉斯快照测试中处理时区?
- android - 房间数据库:创建新的 RecyclerView 项目后两次获取 SELECT MAX()
- mongoose - Mongoose schema "this" keyword returns undefined
- java - How do I get data into a constructor from two different loops
- python - Why won't Python's socket.recv() return -1
- agda - Loading files in Agda: unclear explanation in Learn you an Agda
- r - R Session aborted after querying data from an AWS Athena Table