Azure API Management 是 Azure 提供的网关服务,默认情况下它会打开 CORS 限制。如果按照说明,像下面这样直接设置个 *,尝试用浏览器访问,你会发现浏览器还是会说存在跨域限制。

这个时候的配置 XML 类似于下面的样子:
<policies>
<inbound>
<base />
<cors>
<allowed-origins>
<origin>*</origin>
<origin />
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
解决方案
我们需要把 header 也设置为 *,增加下面这行到配置 xml 中:
<allowed-headers>
<header>*</header>
</allowed-headers>
最后的配置长这样:
<policies>
<inbound>
<base />
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>



被折叠的 条评论
为什么被折叠?



