【发布时间】:2015-09-25 17:02:29
【问题描述】:
我正在使用 Azure API 管理,它在内部访问我的 python Flask Web 服务。 Azure API 适用于 GET 操作。对于 POST,当我进行 jquery AJAX 调用时,请求被转换为 OPTIONS 并出现以下错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://domain.com' is therefore not allowed access. The response had HTTP status code 500.
我为 Azure API 添加了以下策略,
<policies>
<inbound>
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
<base />
</inbound>
<outbound>
<base />
</outbound>
</policies>
但我仍然面临同样的问题。
当我直接向我的 python 烧瓶服务发出 AJAX POST 请求时出现了同样的错误,我通过在烧瓶中添加以下代码来修复它,
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
我应该在 Azure API 管理中进行哪些更改才能使 POST 操作正常工作??
【问题讨论】:
-
我最近注意到我的 Azure api 中的 CORS 失败,截至今天。这也是您最近遇到的问题吗?
-
我们也注意到了它们,从昨天开始。
-
是的。最近的问题,浪费了一整天的时间。微软预计不会
标签: jquery python ajax azure azure-api-management