Ωme*_*Man 3 policy url-rewriting azure azure-api-management
例如context.Variables["accountKey"]在策略重写期间,将简单追加到上下文变量url的方法是什么?
最终结果应为/accounts/232。
我之前设置成功
set-variable (0.003 ms)
{
"message": "Context variable was successfully set.",
"name": "accountKey",
"value": "232"
}
Run Code Online (Sandbox Code Playgroud)
尝试过的一件事:
<policies>
<inbound>
<base />
<rewrite-uri template="/accounts/{accountKey}" />
</inbound>
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误
> Error Receive
> rewrite-uri (0.260 ms) {
> "messages": [
> null,
> "Variable accountKey has no value.",
> "Variable accountKey has no value."
> ] }
Run Code Online (Sandbox Code Playgroud)
如下配置策略中的入站规则:
<inbound>
<base />
<set-variable name="accountKey" value="232" />
<rewrite-uri template="@{
return "/account/" + context.Variables.GetValueOrDefault<string>("accountKey");
}"/>
</inbound>
Run Code Online (Sandbox Code Playgroud)
rewrite-uri中的{}用于原始请求URL中的查询字符串参数。
在https://docs.microsoft.com/zh-cn/azure/api-management/api-management-transformation-policies#RewriteURL上找到有关rewrite-uri的更多详细信息。
| 归档时间: |
|
| 查看次数: |
2415 次 |
| 最近记录: |