azure - 在 Azure API 管理入站策略部分中获取路由参数
问题描述
我有一个带有模板参数的 URL。
https://test.azure-api.net/HelperFunction/{siteId}/lots/InventoryItem/{itemId}
https://test.azure-api.net/HelperFunction/122/lots/InventoryItem/12
我想阅读入站策略部分中的模板/路径参数。
我正在尝试如下。但它只会获取查询字符串参数。我想获取路径参数。
<inbound>
<set-body>@{
JObject transBody = new JObject();
transBody.Add("Arguments",
new JObject
{
{"method", context.Request.Method},
{"parameters", context.Request.Url.QueryString},
});
//Add all json properties as arg
transBody.Add("UriPath", context.Request.Url.Path);
return transBody.ToString();
}</set-body>
<base />
</inbound>
我的要求是将路由参数读取为
"siteId" : 122,
"itemId" : 12
任何帮助,将不胜感激。
解决方案
context.Request.MatchedParameters["siteId"]
和context.Request.MatchedParameters["itemId"]
其余的上下文变量可以在这里找到:https ://docs.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables
推荐阅读
- python - TypeError:预期元指定类型 DataFrame,从 Dask 获得类型 pandas.core.frame.DataFrame
- node.js - 在heroku上部署时前后没有连接
- python - 如果继承的类不正确,请根据我在 `__init__` 函数中尝试实现的内容进行更新
- python - 这个 Matplotlib 代码片段是如何工作的
- click - 如何使用 tablesorter 允许单击位于主题内的按钮?
- html - 如何防止输入数据后调整行大小
- r - 将大列表的元素取消嵌套到数据框中
- javascript - 用 Puppeteer 注入函数
- android - 查找适用于 Android 的单独 REST API 密钥和 MAP SDK 密钥 - mapmyindia API
- lua - 如何使用hammerspoon CLI?