设置基础 URL 总是在后端部分重置



我正在尝试按照以下链接将我的 api 请求转发到 Azure API 管理服务中的另一个基本 URL,该服务是通过从一个 Azure 函数应用导入 API 创建的。

https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-deploy-multi-region

我的策略如下所示

<policies>
<inbound>
<base />
<choose>
<when condition="@(context.Request.OriginalUrl.Host.Contains("centralus-01.regional"))">
<set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
</when>
<when condition="@(context.Request.OriginalUrl.Host.Contains("southeastasia-01.regional"))">
<set-backend-service base-url="https://apiservt.trafficmanager.net/api/" />
</when>
<otherwise>
<set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
</otherwise>
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

但不幸的是,即使我设置了入站策略来更改基本 URL,但应用了入站后策略,该 URL 再次重置为我用于将 API 与 API 管理相关联的原始 Azure 函数。 您可以在跟踪日志中看到,即使将其设置为我所需选择的基本 URL,它也会重置。 我尝试了所有可能的政策组合,但问题仍然存在,请帮助。

api-inspector (0.322 ms)
{
"request": {
"method": "GET",
"url": "https://apiservapimt.azure-api.net/xtxs/sds/",
"headers": [
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": "*****************"
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "X-Forwarded-For",
"value": "188888888888888"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
},
{
"name": "Host",
"value": "apiservapimt.azure-api.net"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
}
]
}
}
api-inspector (0.003 ms)
{
"configuration": {
"api": {
"from": "/",
"to": null,
"version": null,
"revision": "1"
},
"operation": {
"method": "GET",
"uriTemplate": "/jsdhakj/{surveyId}/"
},
"user": "-",
"product": "-"
}
}
cors (0.474 ms)
"Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
choose (0.010 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Request.OriginalUrl.Host.Contains("centralus-01.regional")",
"value": false
}
choose (0.003 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Request.OriginalUrl.Host.Contains("southeastasia-01.regional")",
"value": false
}
set-backend-service (0.005 ms)
{
"message": "Backend service URL was changed.",
"oldBackendServiceUrl": "",
"newBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
"request": {
"url": "https://apiservtmt.trafficmanager.net/api/adhsakjd/sds/"
}
}
**set-backend-service (0.005 ms)
"Backend 'apiservt' set to current."**
**Backend
(668.101 ms)↑ Back to top
set-backend-service (0.030 ms)
{
"message": "Backend service URL was changed.",
"oldBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
"newBackendServiceUrl": "https://apiservt.azurewebsites.net/api",
"request": {
"url": "https://apiservt.azurewebsites.net/api/surveys/sds/"
}
}**
set-header (0.019 ms)
{
"message": "Specified value was assigned to the header (see below).",
"header": {
"name": "x-functions-key",
"value": "hjwjrhewj"
}
}
forward-request (0.101 ms)
{
**"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://apiservt.azurewebsites.net/api/surveys/sds/",
"headers": [**
{
"name": "Host",
"value": "apiservt.azurewebsites.net"
},
{
"name": "Request-Id",
"value": "|9ab257c67368465b904f288b38b44118.c248de116fca4824_83e3e6e7."
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": "wrewrwer"
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "X-Forwarded-For",
"value": "shakjdhkjsa"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
},
{
"name": "Request-Context",
"value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
},
{
"name": "x-functions-key",
"value": "shdsajdhskjf"
}
]
}
}
forward-request (667.950 ms)
{
"response": {
"status": {
"code": 401,
"reason": "Unauthorized"
},
"headers": [
{
"name": "Transfer-Encoding",
"value": "chunked"
},
{
"name": "Request-Context",
"value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Tue, 24 Sep 2019 17:40:07 GMT"
}
]
}
}
Outbound
(0.146 ms)↑ Back to top
transfer-response (0.050 ms)
{
"message": "Response headers have been sent to the caller."
}
transfer-response (0.096 ms)
{
"message": "Response body streaming to the caller is complete."
}

现在解决了。 从 Azure 函数导入 API 时,在每个操作级别添加了另一个设置基本 URL 策略。通过删除这些策略,选择了父策略。

最新更新