【问题标题】:How do I add in bound processing policy in APIM?如何在 APIM 中添加绑定处理策略?
【发布时间】:2019-04-30 05:14:15
【问题描述】:

我正在尝试将以下绑定处理策略添加到我的 APIM 以进行操作:

<policies>
    <inbound>
        <base />
        <rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&amp;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}&amp;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 参数期望的格式是什么?

【问题讨论】:

    标签: azure powershell azure-api-management


    【解决方案1】:

    我可以重现您的问题,-Policy 参数的格式似乎是正确的,问题是由您的策略中的rewrite-uri 引起的。

    &lt;rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&amp;amp;AppointmentType={AppointmentType}" /&gt;

    我用官方文档中的示例进行了测试,效果很好。

    <rewrite-uri template="/put" />
    

    更多rewrite-uri的使用方法可以参考这个link

    【讨论】:

      【解决方案2】:

      感谢 Joy Wang 为我指明了正确的方向,这是解决方案:

      我尝试直接通过门户添加 XML,并收到此错误:

      一个或多个字段包含不正确的值:元素错误 第 4 行第 10 列的“rewrite-uri”:仅在 可以在重写模板中使用原始 URL 模板

      原来我所指的参数(StartDateTimeAppointmentType)不是 APIM 中模板参数的一部分。

      一旦我将它们作为模板参数添加到 APIM 中,该命令就起作用了。

      如果 Powershell 命令行开关返回与 Azure 门户相同的错误,而不仅仅是“BadRequest”,那就太好了

      【讨论】:

      • 您能接受我的回复作为答案吗?无论如何,我认为我的回复指出了错误并纠正了您的方向。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2020-10-29
      • 2018-12-18
      • 2018-10-22
      • 2017-08-28
      • 2022-01-07
      相关资源
      最近更新 更多