【问题标题】:Azure API management POST request - All body parameters requiredAzure API 管理 POST 请求 - 需要所有正文参数
【发布时间】:2021-06-22 02:29:51
【问题描述】:

如何验证我的发布请求需要正文中的所有请求参数?我可以使用哪些策略表达? 我正在使用以下表达式:

<policies>
<inbound>
    <base />
    <choose>
        <when condition="@((context.Request.Body) != null&& ((int)context.Request.Body.As<JObject>()["Id"])>0)">
            <return-response>
            </return-response>
        </when>
        <otherwise>
            <return-response>
            </return-response>
        </otherwise>
    </choose>
</inbound>

我如何限制为这个帖子请求输入所有正文参数?

【问题讨论】:

标签: azure azure-api-management


【解决方案1】:

请参阅 APIM 的内容验证政策:https://docs.microsoft.com/en-us/azure/api-management/validation-policies#validate-content 它们允许您验证请求是否真正符合规范中指定的架构。

作为替代方案,您可以将 body 读取为 JObject 并手动检查每个感兴趣的属性。请注意,您要使用 context.Request.Body.As(preserveContent: true) 来确保正文被缓存并可用于稍后发送到后端。

【讨论】:

  • 很高兴您提到了 preserveContent - 与此相关的文档并不容易找到,因为它应该是
  • 更新答案以引用 APIM 提供的新内容验证策略
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-11
  • 2019-01-03
  • 2022-08-18
  • 1970-01-01
相关资源
最近更新 更多