【发布时间】:2021-05-05 03:07:19
【问题描述】:
我正在尝试设置 Azure API,但无论我做什么,CORS 标头都不会添加到我的响应中。我也试过只添加一个随机标题,但这也不起作用。
我在 S/O 和其他地方看到过多个其他帖子,据我所知,我的政策是正确的。还有什么我需要做的吗?下面是计算出的操作的有效策略。这是一个简单的 GET,尽管我也尝试使用具有相同结果的 POST。当我从 Postman 调用 API 并在标头中指定我的 SubscriptionKey 时,我会返回模拟策略中指定的 201 响应,但没有其他标头。 Fiddler 确认响应不包含 CORS 或我的 X-WTF 标头。
当我从 APIM 中的测试选项卡调用 API 时,它也成功了 201,但没有额外的标头。
<policies>
<inbound>
<!-- base: Begin Api scope -->
<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>
<!-- base: End Api scope -->
<mock-response status-code="201" content-type="application/json" />
</inbound>
<backend>
<!-- base: Begin Api scope -->
<!-- base: Begin Product scope -->
<!-- base: Begin Global scope -->
<forward-request />
<!-- base: End Global scope -->
<!-- base: End Product scope -->
<!-- base: End Api scope -->
</backend>
<outbound>
<!-- base: Begin Api scope -->
<set-header name="X-WTF" exists-action="override">
<value>147852</value>
</set-header>
<!-- base: End Api scope -->
</outbound>
<on-error />
【问题讨论】: