【问题标题】:Azure API Management: Replace querystring parameter nameAzure API 管理:替换查询字符串参数名称
【发布时间】:2019-04-05 22:54:35
【问题描述】:

APIM 新手。尝试使用后端 api 期望的不同名称更改公开的查询字符串参数名称(而不是值)

例如,APIM 端点需要 /v1/Customer?CustomerId=123

我认为我需要在入站部分使用 rewrite-url 策略?

要将其更改为:/v1/Customer?ExternalCustomerId=123


试过了,不行

<set-query-parameter name="ExternalCustomerId" exists-action="append">
        <value>@(Context.Request.QueryString["CustomerId"])</value>
    </set-query-parameter>

错误:当前上下文中不存在名称“上下文”

【问题讨论】:

    标签: url-rewriting azure-api-management


    【解决方案1】:

    自 2019 年 9 月起,这已发生变化。现在使用以下内容:

    <set-query-parameter name="ExternalCustomerId" exists-action="append">
        <value>@(context.Request.Url.Query.GetValueOrDefault("CustomerId"))</value>
    </set-query-parameter>
    

    【讨论】:

      【解决方案2】:

      尝试小写“上下文”。 Plus QueryString 是一个 IReadOnlyDictionary,如下所述:https://docs.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables,但有一个方便的重载:

      <set-query-parameter name="ExternalCustomerId" exists-action="append">
          <value>@(context.Request.QueryString.GetValueOrDefault("CustomerId"))</value>
      </set-query-parameter>
      

      【讨论】:

        猜你喜欢
        • 2018-02-22
        • 2013-08-03
        • 2013-02-06
        • 1970-01-01
        • 1970-01-01
        • 2010-12-02
        • 2020-06-21
        • 1970-01-01
        • 2014-03-30
        相关资源
        最近更新 更多