如何在 Azure API 管理中为查询字符串参数指定重写 url

Phi*_*gan 5 azure azure-api-management

我正在使用 Azure API 管理将传入的查询字符串转换为另一个查询字符串。

我的转换代码是:

<policies>
    <inbound>
        <rewrite-uri template="api/primes?a={a}&b={b}" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
Run Code Online (Sandbox Code Playgroud)

当我尝试保存编辑时,出现错误:

One or more fields contain incorrect values: 
'=' is an unexpected token. The expected token is ';'. Line 15, position 50.
Run Code Online (Sandbox Code Playgroud)

它指的是 中的等号符号a={a}。如何更正 的模板rewrite-uri?输入 url 是例如https://example.com/sum?a=7&b=5.

Eva*_*ula 9

尝试更换:

<rewrite-uri template="api/primes?a={a}&b={b}" />
Run Code Online (Sandbox Code Playgroud)

和:

<rewrite-uri template="api/primes?a={a}&amp;b={b}" />
Run Code Online (Sandbox Code Playgroud)

https://azure.microsoft.com/en-us/blog/policy-expressions-in-azure-api-management/ 中查找更多详细信息。