[英]How to specify rewrite url for query string parameters in Azure API Management
我正在使用Azure API Management将传入的查询字符串转换为另一个查询字符串。
我的转换代码是:
<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>
当我尝试保存编辑时,出现错误:
One or more fields contain incorrect values:
'=' is an unexpected token. The expected token is ';'. Line 15, position 50.
它指的是a={a}
的等号。 如何更正rewrite-uri
的模板? 输入网址例如是https://example.com/sum?a=7&b=5
。
尝试更换:
<rewrite-uri template="api/primes?a={a}&b={b}" />
附:
<rewrite-uri template="api/primes?a={a}&b={b}" />
有关详细信息, 请访问https://azure.microsoft.com/en-us/blog/policy-expressions-in-azure-api-management/ 。
您只需要在APIM中创建“ 查询参数 ”而不是“模板参数”。 然后你的重写uri不需要包含Query参数,因为APIM会在通过入站提供后自动将其添加到后端url。
<rewrite-uri template="api/primes" />
如果请求URL是这样的:
https://example.com/sum?a=7&b=5
然后发送到后端的HTTP请求将是这样的:
GET backendapi/api/primes?a=7&b=5
如果请求URL没有像这样的查询字符串:
https://example.com/sum
那么发送到后端的HTTP请求就像这样:
GET backendapi/api/primes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.