【问题标题】:Azure API Management Rate Limit By Json BodyAzure API 管理速率限制(按 Json 正文)
【发布时间】:2021-01-04 09:45:13
【问题描述】:

您好,我正在尝试通过 json 正文值对 azure api 管理应用速率限制,我有这样的规则

<rate-limit-by-key calls="6" renewal-period="180" counter-key="@(context.Request.Body.As<JObject>()["phoneNumber"].ToString())" increment-condition="@(context.Response.StatusCode >= 200 && context.Response.StatusCode < 300)" />

但速率限制不起作用。

【问题讨论】:

    标签: azure ratelimit apim


    【解决方案1】:

    我的测试成功了。

    请求正文:

    {
       "phoneNumber": "+1234"
    }
    

    政策:

        <inbound>
          <base />
          <rate-limit-by-key calls="6" renewal-period="180" counter-key="@(context.Request.Body.As<JObject>()["phoneNumber"].ToString())" increment-condition="@(context.Response.StatusCode >= 200 && context.Response.StatusCode < 300)" />
          <return-response>
            <set-status code="200" reason="OK" />
            <set-body />
          </return-response>
        </inbound>
    

    return-response 仅用于测试。

    几次尝试后的响应正文:

    {
      "statusCode": 429,
      "message": "Rate limit is exceeded. Try again in 174 seconds."
    }
    

    这与您的实施有何不同?
    你有不同的请求正文吗?

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 2012-11-15
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多