我正在使用内部访问我的 python Flask Web 服务的 Azure API 管理。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 操作正常工作?