【发布时间】:2020-05-15 15:44:44
【问题描述】:
使用 Azure API 管理中的策略,我正在尝试重命名查询参数,但它不起作用。如果我将 copy-unmatched-params="false" 更改为 copy-unmatched-params="true" 那么它可以工作,但是行为变成所有不匹配的参数都将传递给后端 API,这将允许客户端注入他们自己的查询将参数放入我们不想要的后端请求中。
其他一切都很好。
我想转换一个如下所示的请求:
https://{site}/search?query=dylan
收件人:
https://{backend-site}documents?api-version=2018-1-11&amount=1000&searchFields=Album,Artist&search=dylan
唯一不起作用的部分是将查询参数转换为名为“搜索”而不是查询,而不允许从入站查询字符串传递所有参数。我该如何解决?
<policies>
<inbound>
<rewrite-uri template="/" copy-unmatched-params="false" />
<set-header name="api-key" exists-action="override">
<value>THIS-IS-API-KEI</value>
</set-header>
<set-query-parameter name="api-version" exists-action="override">
<value>2018-1-11</value>
</set-query-parameter>
<set-query-parameter name="amount" exists-action="override">
<value>1000</value>
</set-query-parameter>
<set-query-parameter name="searchFields" exists-action="override">
<value>Album,Artist</value>
</set-query-parameter>
<set-query-parameter name="search" exists-action="override">
<value>@(context.Request.Url.Query.GetValueOrDefault("query"))</value>
</set-query-parameter>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
【问题讨论】:
标签: azure azure-api-management