gpt4 book ai didi

azure - CORS - 在 Azure API 管理上启用了 localhost 原点,但仍然收到错误

转载 作者:行者123 更新时间:2023-12-02 06:38:40 24 4
gpt4 key购买 nike

我正在尝试测试从通过 Azure API 管理配置的团队 API 检索数据。我在本地托管客户端 Web 应用程序(一个 create-react-app 项目),该应用程序将调用 API,并在 APIM 中为我的本地主机启用 CORS 策略。我已在 APIM 中添加了所有操作的入站策略: enter image description here

我使用 CORS 策略中启用的相同 header 和方法调用 API。

enter image description here

但是我仍然遇到“请求的资源上不存在‘Access-Control-Allow-Origin’ header ”的问题。我不想使用插件,因为这并不能真正解决大问题,而且我不能使用通配符,因为“Allow-Credentials”必须设置为 true。我看过这个问题的很多版本,但没有任何帮助。有谁知道我可能会错过什么?

最佳答案

重申 derpirscher 对其他人的回答:我需要将选项添加到允许的方法中,因为 preflight Options请求已发送:

<cors allow-credentials="true">
<allowed-origins>
<origin>http://localhost:3000</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
</allowed-methods>
<allowed-headers>
<header>content-type</header>
<header>accept</header>
<header>authorization</header>
<header>options</header>
</allowed-headers>
</cors>

关于azure - CORS - 在 Azure API 管理上启用了 localhost 原点,但仍然收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68231187/

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