Azure API 管理服务更新 CORS 以允许 OPTIONS

Azure API Management Services updating CORS to allow OPTIONS

我已经在 apim 中设置了一个 POST 端点,我可以测试它在绕过 apim 时是否工作正常 - 但是当我从我的站点调用它时,我得到了 200 空响应以及Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://apim.azure-api.net/project. (Reason: CORS header “Access-Control-Allow-Origin” missing)

我相信这是因为“当 OPTIONS 请求作为飞行前请求处理并且与 CORS 策略设置不匹配时:立即以空的 200 OK 响应终止请求”——基于此处的文档: https://docs.microsoft.com/en-us/azure/api-management/api-management-cross-domain-policies 属性 terminate-unmatched-request 默认为 true - 当我尝试在策略中将其设置为 false 时,它没有被保存,例如:

<policies>
    <inbound>
        <base />
        <cors terminate-unmatched-request="false">
            <allowed-origins>
                <origin>*</origin>
            </allowed-origins>
            <allowed-methods>
                <method>OPTIONS</method>
                <method>POST</method>
            </allowed-methods>
            <allowed-headers>
                <header>*</header>
            </allowed-headers>
        </cors>
    </inbound>
    ...

结果:

<policies>
    <inbound>
        <base />
        <cors>
            <allowed-origins>
                <origin>*</origin>
            </allowed-origins>
            <allowed-methods>
                <method>OPTIONS</method>
                <method>POST</method>
            </allowed-methods>
            <allowed-headers>
                <header>*</header>
            </allowed-headers>
        </cors>
    </inbound>
    ...

所以我想知道这是否需要在其他地方设置,或者我是否需要以不同方式更新我的策略以允许 OPTIONS 预检请求?

由于问题已在评论中解决,因此将其添加为答案以帮助其他人。

I moved my CORS policy from the specific Operation to the All operations level and that seemed to work.