Azure API管理CORS:为什么我得到;以'开头的标题;访问控制&x27;已被删除……”;

Azure API管理CORS:为什么我得到;以'开头的标题;访问控制&x27;已被删除……”;,azure,cors,azure-api-management,Azure,Cors,Azure Api Management,下面是一个简单的策略: <policies> <inbound> <cors> <allowed-origins> <origin>http://microfost.com/</origin> </allowed-origins> <allowed-methods prefligh

下面是一个简单的策略:

<policies>
    <inbound>
        <cors>
            <allowed-origins>
                <origin>http://microfost.com/</origin>
            </allowed-origins>
            <allowed-methods preflight-result-max-age="300">
                <method>GET</method>
                <method>POST</method>
                <method>PATCH</method>
                <method>DELETE</method>
            </allowed-methods>
            <allowed-headers>
                <header>content-type</header>
                <header>accept</header>
                <header>Authorization</header>
            </allowed-headers>
        </cors>
    </inbound>
</policies>  
在我看来,这似乎是一种胡说八道的行为,可能是一种错误。在提交之前,我想问你是否有任何解释?为什么我会得到这个

从中删除了以“访问控制-”开头的标题 答复


在Azure API管理中有两种执行CORS的方法。自动-只需在所需范围内删除并配置CORS策略,APIM将负责响应与现有操作匹配的选项请求

或者您可以选择手动方式—创建一个单独的操作,该操作响应策略中的选项方法并手动形成响应,可能使用返回响应策略

你的问题是因为你两者都有。他们基本上处于冲突之中。CORS策略将请求标识为跨来源,并在请求完成后安排处理,但选项操作级别上的返回响应策略会中断此处理管道,并在CORS策略可以采取操作之前立即返回响应


由于您使用的是CORS策略,您应该从API中删除选项操作以使其正常工作。

在标记CORS中添加atrrib
allow credentials=“true”

见:
我也遇到了类似的问题。添加
为我修复了它



这就是您得到的全部回复吗?您应该获得Access Control Allow标头、Access Control Allow Origin、Access Control Max Age和Access Control Allow Methods标头。但不仅仅是“起源”。CORS规范()将源代码描述为仅请求标头。是。这就是我得到的全部答复。我缺少的是您提到的标题。请尝试将添加到入站策略中,以便调用更高级别的策略。虽然调用更高级别的策略是一种很好的做法,但在这种情况下,我故意取消了它,但您可以看到一些神秘的出站策略仍然适用。您完全正确,我们进行了测试,结果成功了。尽管仍然令人不安的是,创建的第一个API即使使用了额外选项策略也能正常工作。我想说的是,文档不清楚如何配置它()。谢谢你的回答!
OPTIONS https://XXXX.azure-api.net/demo/XXX/XXX/* HTTP/1.1
Host: XXXX.azure-api.net
Ocp-Apim-Trace: true
Ocp-Apim-Subscription-Key: <secret>
Origin: http://microfost.com
Access-Control-Request-Headers: Authorization
Access-Control-Request-Method: GET
Access-Control-Allow-Origin: http://microfost.com
Ocp-Apim-Trace-Location: <trace>
Date: Mon, 27 Feb 2017 20:09:14 GMT
Content-Length: 0
**Inbound**
[...]
cors (0 ms)
"Cross domain request was well formed and was allowed to proceed. CORS related headers were added to the response."

**Backend**

No records.
Outbound

cors (0 ms)
{
    "message": "Headers starting with 'Access-Control-' were removed from the response. ",
    "headers": []
}
transfer-response (0 ms)
{
    "message": "Response headers have been sent to the caller."
}