Azure APIM:新的开发人员门户需要 CORS 来测试 API



我正在尝试在Azure APIM中配置我的API,以便新的Azure APIM开发人员门户(目前仍处于预览状态(可以调用它。 当我尝试从开发人员门户调用 API 时,出现错误,提示我需要配置 CORS 以允许从开发人员门户调用。 我将 CORS 策略添加到我的 API(origin = *,用于测试目的(,但我仍然遇到同样的问题。 我错过了什么吗?

您可能想要调整它,但这应该可以解决问题:

<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
<expose-headers>
<header>*</header>
</expose-headers>
</cors>

我在所有 API 操作级别执行此操作,并且必须包含"访问控制-允许源"标头。

<cors allow-credentials="true">
<allowed-origins>
<origin>*YourDomain*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
<allowed-headers>
<header>Ocp-Apim-Subscription-Key</header>
<header>Access-Control-Allow-Origin</header>
<header>Content-Type</header>
</allowed-headers>
</cors>

以下是应应用的确切策略:

<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
<method>PUT</method>
<method>DELETE</method>
<method>HEAD</method>
<method>OPTIONS</method>
<method>PATCH</method>
<method>TRACE</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
<expose-headers>
<header>*</header>
</expose-headers>
</cors>

来源: https://github.com/Azure/api-management-developer-portal/issues/290#issuecomment-551088484

最新更新