gpt4 book ai didi

Azure API 管理 : Origin header was missing or empty and the request was classified as not cross-domain. CORS 策略未应用

转载 作者:行者123 更新时间:2023-12-02 05:55:50 24 4
gpt4 key购买 nike

我正在使用 Azure API 管理,并且需要使用它来管理三个 API。测试时,GET 方法工作正常,但是 post 方法出现以下错误:

Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied.

我四处搜索并发现了 CORS 和 APIM 的许多问题,但到目前为止我还没有看到我的具体问题。

当前 CORS 策略的配置为

<policies>
<inbound>
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
</inbound>
<backend>
<forward-request />
</backend>
<outbound />
<on-error />
</policies>

我在以下地方寻找答案:

https://learn.microsoft.com/en-us/azure/api-management/api-management-cross-domain-policies

Azure API Management CORS: Why do I get "Headers starting with 'Access-Control-' were removed..."

https://briancaos.wordpress.com/2018/04/05/azure-api-management-configure-cors-in-the-policy/

我的问题是1. 我需要如何制定我的 CORS 政策,2. 我是否需要在 API Startup.cs 或配置文件中添加任何内容来处理 CORS?

谢谢?

最佳答案

截至 2020 年底,除了通过 XML 策略配置此选项的选项之外,如 stated in the docs ,现在还有一种在 Azure 门户中配置此功能的可视化方法。

  1. 在 Azure 门户的 Azure API 管理部分打开您的 API
  2. 选择所有操作或单个操作
  3. 在右侧选择入站处理> 添加政策

Select "Add policy"

  • 您将获得预制策略模板列表。选择“CORS”并随意配置:
  • Select options for CORS

    这应该涵盖您问题的“如何制定政策”部分。甚至可以在全局范围内将 CORS 等策略应用于所有 API。

    关于Azure API 管理 : Origin header was missing or empty and the request was classified as not cross-domain. CORS 策略未应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62040830/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com