Azure APIM验证 - 包含入站政策,验证请求主体

发布于 2025-02-03 20:05:47 字数 923 浏览 4 评论 0原文

我的API在APIM中,我需要验证请求有效负载主体(JSON格式),以提高要求。

我遵循了这个步骤 https://learlen.microsoft.com/en-en---en----我们/azure/api管理/验证 - 属性#属性

我在模式中添加了适当的JSON模式: -

我已经在入站策略中添加了下面的策略,上述 schemaid 和上述创建的模式。

 <validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent" errors-variable-name="requestBodyValidation">
        <content type="application/json" validate-as="json" action="detect" schema-id="Postschema" />
    </validate-content>

即使遵循上述步骤,如果我对无效的JSON提出请求,我仍会收到200个成功响应。我想念什么?

I have api's in APIM, i need to validate request payload body(Json Format) foreach Post Request.

I followed steps from this
https://learn.microsoft.com/en-us/azure/api-management/validation-policies#attributes

I have added proper json schema in Schemas :-
enter image description here

and i have added below policy in Inbound policy, mentioned schemaid with the above created schema.

 <validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent" errors-variable-name="requestBodyValidation">
        <content type="application/json" validate-as="json" action="detect" schema-id="Postschema" />
    </validate-content>

Even after following above steps, if i make request with invalid json, i am still receiving 200 success response. What am i missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美煞众生 2025-02-10 20:05:47

请将操作将操作更改为 forcorm-type application> application/json 。

您还可以将操作更改为检测 未指定的content-type-action,如果您想允许不带有content-type的请求application> application> application/json

actions

检测:日志验证错误,而不会中断请求或响应处理。

预防:阻止请求或响应处理,记录详细的验证错误,然后返回错误。检测到第一组错误时,处理中断处理。

<validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent" errors-variable-name="requestBodyValidation">
        <content type="application/json" validate-as="json" action="prevent" schema-id="Postschema" />
</validate-content>

Please change the action detect to prevent for content-type application/json.

You can also change the action to detect for unspecified-content-type-action if you want to allow requests without content-type application/json.

Actions:

detect: Log validation errors, without interrupting request or response processing.

prevent: Block the request or response processing, log the verbose validation error, and return an error. Processing is interrupted when the first set of errors is detected.

<validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent" errors-variable-name="requestBodyValidation">
        <content type="application/json" validate-as="json" action="prevent" schema-id="Postschema" />
</validate-content>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文