【问题标题】:Azure APIM getting CORS error on API Post methodAzure APIM 在 API Post 方法上出现 CORS 错误
【发布时间】:2021-08-26 16:39:18
【问题描述】:

我正在尝试在我的 Web 应用程序中使用 POST API 并出现错误: 从源“http://localhost:3030”访问“https://XXXXX”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“访问控制允许来源” ' 请求的资源上存在标头。

以下是 API 级别 APIM 中的 CORS 设置:

<policies>
<inbound>
    <base />
    <cors allow-credentials="true">
        <allowed-origins>
            <origin>http://localhost:3030/</origin>
            
        </allowed-origins>
        <allowed-methods preflight-result-max-age="300">
            <method>GET</method>
            <method>POST</method>
            <method>OPTIONS</method>
        </allowed-methods>
        <allowed-headers>
            <header>*</header>
        </allowed-headers>
    </cors>
</inbound>
<backend>
    <base />
</backend>
<outbound>
    <base />
</outbound>
<on-error>
    <base />
</on-error>

我不确定这里的设置有什么问题。快速帮助将不胜感激!

提前致谢。

【问题讨论】:

  • 从 http 到 https 的请求会导致混合内容错误,一些客户端会感到困惑并将其显示为 CORS 错误,请尝试 https 到 https,看看这是否有助于解决问题,

标签: cors azure-web-app-service azure-api-management


【解决方案1】:

您应该在 Azure app servicesAPIM 中都配置 CROS。

从你的api设置来看,应该没有问题。请检查您的 webapp 中的跨域设置。

更多详情,您可以参考以下帖子来定位您的问题。

1. Failed to call APIs from web page behind Azure APIM due to CORS issues

2. Getting Access Control Allow Origin Error While Accessing Web Api hosted in AZURE RRS feed

【讨论】:

    猜你喜欢
    • 2019-12-28
    • 1970-01-01
    • 2016-05-27
    • 2018-04-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多