使用Azure门户,我无法向Echo API (和所有其他后端API)发送测试请求。
发送请求时,我将得到以下错误:
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策略:
<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错误?
发布于 2022-04-12 13:05:27
ByPass CORS选项允许来自任何域的请求。有时,允许跨域访问也解决了这个问题。尝试Azure跨域策略,如下所示,允许从“任意”域访问(您也可以指定您的域)。
<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
https://stackoverflow.com/questions/71837577
复制相似问题