首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用Azure APIM交互式门户向后端APIM发送测试请求

无法使用Azure APIM交互式门户向后端APIM发送测试请求
EN

Stack Overflow用户
提问于 2022-04-12 05:34:56
回答 3查看 543关注 0票数 1

使用Azure门户,我无法向Echo API (和所有其他后端API)发送测试请求。

发送请求时,我将得到以下错误:

代码语言:javascript
运行
复制
HTTP/1.1 401 Access Denied
cache-control: private, s-maxage=0
content-length: 152
content-type: application/json
date: Tue, 12 Apr 2022 05:13:28 GMT
vary: Origin
www-authenticate: AzureApiManagementKey realm="https://AAAA.azure-api.net/echo",name="Ocp-Apim-Subscription-Key",type="header"
    {
    "statusCode": 401,
    "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API."
}

当我勾选“旁路代理”复选框并通过邮递员时,请求可以正常工作。

我有以下全球入站CORS策略:

代码语言:javascript
运行
复制
<policies>
    <inbound>
        <cors allow-credentials="true">
            <allowed-origins>
                <origin>https://AAAA.developer.azure-api.net</origin>
                <origin>https://AAAA.azure-api.net</origin>
            </allowed-origins>
            <allowed-methods preflight-result-max-age="300">
                <method>*</method>
            </allowed-methods>
            <allowed-headers>
                <header>*</header>
            </allowed-headers>
            <expose-headers>
                <header>*</header>
            </expose-headers>
        </cors>
    </inbound>
    <backend>
        <forward-request />
    </backend>
    <outbound />
    <on-error />
</policies>

以及Echo上的入站基本策略集。

我以前没有经历过这个问题。有什么想法吗?在APIM门户中提交测试请求时,如何通过CORS错误?

EN

Stack Overflow用户

发布于 2022-04-12 13:05:27

ByPass CORS选项允许来自任何域的请求。有时,允许跨域访问也解决了这个问题。尝试Azure跨域策略,如下所示,允许从“任意”域访问(您也可以指定您的域)。

代码语言:javascript
运行
复制
<cross-domain>
<cross-domain-policy>
    <allow-http-request-headers-from domain='*' headers='*' />
</cross-domain-policy>

有关详细信息,请参阅管理跨域访问的MS文档:https://learn.microsoft.com/en-us/azure/api-management/api-management-cross-domain-policies

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71837577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档