我已经用 Python 实现了一个 Azure 函数,该函数仅适用于 Azure Linux 服务器。使用 Visual Studio Code,我设法在本地运行这些函数,并使用 postman 执行测试,请求成功运行。我还使用 Visual Studio Code 将这些函数部署到 Azure,并再次使用 Postman 测试了公共(public) REST API 主机,它成功了。
问题是通过我的 Web 应用程序调用此 API,该应用程序返回了 CORS 错误。 我知道这是正常的,因为我没有通过 Azure 面板在 CORS 中设置允许所有 (*) 属性。基本上,因为 CORS 被阻止:
当我点击时,我收到以下警告:
This feature is not supported for Linux apps on a Consumption plan
我尝试在 python 函数中添加 header ,例如:
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]
关于azure - 无法在 Azure Functions Linux 消耗计划上编辑 CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288228/