gpt4 book ai didi

azure - APIM - 验证消费层的内容

转载 作者:行者123 更新时间:2023-12-03 05:24:04 28 4
gpt4 key购买 nike

我最近将 APIM 实例从开发人员层更改为消费层,并且在验证内容策略中看到了一些奇怪的行为。在开发人员层,此策略将按预期工作并返回 400 错误以及相应的错误消息。

以下是政策:

<validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent">
<content type="application/json" validate-as="json" action="prevent" />
</validate-content>

下面是来自开发人员层的跟踪和响应的示例(预期行为):

//Trace
validate-content (0.100 ms)
{
"name": "application/json",
"type": "RequestBody",
"validationRule": "IncorrectMessage",
"details": "Body of the request does not conform to the definition skills-POST-request, which is associated with the content type application/json. Property 'nam' has not been defined and the schema does not allow additional properties. Line: 1, Position: 7",
"action": "Prevented"
}

//Response
HTTP/1.1 400 Bad Request
vary: Origin
{
"statusCode": 400,
"message": "Body of the request does not conform to the definition skills-POST-request, which is associated with the content type application/json. Property 'nam' has not been defined and the schema does not allow additional properties. Line: 1, Position: 7"
}

但是,现在消费层上的相同策略返回以下跟踪和响应(不正确的行为):

//Trace
validate-content (4.736 ms)
{
"name": "application/json",
"type": "RequestBody",
"validationRule": "IncorrectMessage",
"details": "Body of the request does not conform to the definition skills-POST-request, which is associated with the content type application/json. Property 'nam' has not been defined and the schema does not allow additional properties. Line: 1, Position: 7",
"action": "Prevented"
}
validate-content (0.714 ms)
{
"name": null,
"type": "RequestBody",
"validationRule": "ValidationException",
"details": "Body of the request cannot be validated for the content type application/json. Value cannot be null.\r\nParameter name: key",
"action": "Prevented"
}
validate-content (2.679 ms)
{
"messages": [
"Value cannot be null.\r\nParameter name: key"
]
}

//response
HTTP/1.1 500 Internal Server Error
vary: Origin
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "b3d76aed-fdf0-4240-a5c1-db49fed82105"
}

这看起来可能是消费层的内容验证策略中的某种错误?

最佳答案

我向 Microsoft 提出了支持请求,他们确定这是 API 管理中的错误。解决方法是将以下内容添加到策略中:

errors-variable-name="requestBodyValidation"

所以最终的政策现在看起来像:

<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" />
</validate-content>

关于azure - APIM - 验证消费层的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70268178/

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