0)"> -6ren">
gpt4 book ai didi

Azure API 管理 POST 请求 - 需要所有正文参数

转载 作者:行者123 更新时间:2023-12-01 11:21:52 24 4
gpt4 key购买 nike

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

<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://learn.microsoft.com/en-us/azure/api-management/validation-policies#validate-content它们允许您验证该请求实际上符合规范中指定的架构。

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

关于Azure API 管理 POST 请求 - 需要所有正文参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53744340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com