我正在尝试将绑定处理策略中的以下内容添加到我的APIM进行操作:
<policies>
<inbound>
<base />
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
<set-header name="ocp-apim-subscription-key" exists-action="override">
<value>12d0bdd57ca84fa9ad35f13f22605dbf</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
我找到了这个命令行开关,但是没有关于放入-Policy
的内容的信息。
我尝试过使用以下内容
$policyString = '<policies>
<inbound>
<base />
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
<set-header name="ocp-apim-subscription-key" exists-action="override">
<value>12d0bdd57ca84fa9ad35f13f22605dbf</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>'
Set-AzureRmApiManagementPolicy -Context $apiMgmtContext -ApiId $apiId -Policy $policyString -OperationId 'GetCalendar'
但它给了我这个错误:
Operation returned an invalid status code 'BadRequest'
政策参数的期望是什么格式?
我可以重现你的问题,-Policy
参数的格式似乎是正确的,问题是由你的政策中的rewrite-uri
引起的。
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
我用官方文档中的示例测试它,它工作正常。
<rewrite-uri template="/put" />
有关rewrite-uri
用法的更多详细信息,请参阅此link。
感谢Joy Wang指出我正确的方向,这是解决方案:
我尝试通过门户直接添加XML,并收到此错误:
一个或多个字段包含不正确的值:第4行,第10列元素'rewrite-uri'中的错误:只能在重写模板中使用原始URL模板中指定的参数
原来我所指的参数(StartDateTime
和AppointmentType
)不是APIM模板参数的一部分。
一旦我将它们作为模板参数添加到APIM中,该命令就可以了。
如果Powershell命令行开关返回与Azure门户相同的错误,而不仅仅是'BadRequest',那将会很好