Azure API 管理 POST 请求 - 需要所有正文参数
Azure API management POST request - All body parameters required
如何验证我的 post 请求需要正文中的所有请求参数?我可以使用哪些政策表述?
我正在使用以下表达式:
<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>
如何限制输入此 post 请求的所有正文参数?
查看 APIM 的内容验证策略:https://docs.microsoft.com/en-us/azure/api-management/validation-policies#validate-content它们允许您验证该请求是否确实符合您的规范中指定的架构。
作为替代方案,您可以将 body 读取为 JObject 并手动检查每个感兴趣的 属性。请注意,您要使用 context.Request.Body.As(preserveContent: true) 来确保正文被缓存并可用于稍后发送到后端。
如何验证我的 post 请求需要正文中的所有请求参数?我可以使用哪些政策表述? 我正在使用以下表达式:
<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>
如何限制输入此 post 请求的所有正文参数?
查看 APIM 的内容验证策略:https://docs.microsoft.com/en-us/azure/api-management/validation-policies#validate-content它们允许您验证该请求是否确实符合您的规范中指定的架构。
作为替代方案,您可以将 body 读取为 JObject 并手动检查每个感兴趣的 属性。请注意,您要使用 context.Request.Body.As(preserveContent: true) 来确保正文被缓存并可用于稍后发送到后端。