azure - Azure API 管理 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>
如何限制输入此帖子请求的所有正文参数?
解决方案
请参阅 APIM 的内容验证策略:https ://docs.microsoft.com/en-us/azure/api-management/validation-policies#validate-content它们允许您验证该请求实际上是否符合规范中指定的架构。
作为替代方案,您可以将 body 读取为 JObject 并手动检查每个感兴趣的属性。请注意,您要使用 context.Request.Body.As( preserveContent: true ) 来确保正文被缓存并可用于稍后发送到后端。
推荐阅读
- macos - macOS Big Sur 中的分段错误后未生成核心转储文件
- google-cloud-platform - 如何避免找不到文件(WinError 3)?
- curve - 如何在 Maxima CAS 中绘制旋转椭圆?
- pandas - 获取索引前 n 天的行子集
- pine-script - 如何在查看 Heikin Ashi 图表时获取 OHLC 蜡烛值?
- reactjs - Jest/React/Mobx:TypeError mobxReact.observer 不是函数
- shell - Ansible 显示项目在循环中未定义
- reactjs - 使用 React Native Paper 为 iOS 和 Android 的不同屏幕正确缩放字体需要考虑哪些不同的参数?
- python - ConvergenceError:由于矩阵求逆问题导致收敛停止
- powerbi - 如何在DAX(power bi)中计算当前日期时间和给定日期时间之间的小时数