Azure API 管理中的 CORS 问题

Sel*_*lva 6 python ajax jquery azure azure-api-management

我正在使用 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.
Run Code Online (Sandbox Code Playgroud)

我为 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>
Run Code Online (Sandbox Code Playgroud)

但我仍然面临着同样的问题。

当我直接向 python Flask 服务发出 AJAX POST 请求时,出现了相同的错误,我通过在 Flask 中添加以下代码来修复它:

@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
Run Code Online (Sandbox Code Playgroud)

我应该在 Azure API 管理中更改哪些内容才能使 POST 操作正常工作?

JJ.*_*JJ. 1

上一个版本中存在 CORS 错误,现已解决。