为什么在入站策略中使用 xml-to-json 策略会导致主体为空?

Why does the xml-to-json policy result in an empty body when using it in the inbound policies?

文档参考:https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#example-1

我的 "inbound processing" 政策中的一个片段:

<inbound>
   <base />
   <xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</inbound>

问题: 当我在 "inbound processing" 中应用此策略时,调用的后端 API (Logic App) 被赋予一个空体。 API 收到此请求显示 Content-Length = 0.

跟踪结果:

xml-to-json (0.697 ms)
"XML-to-JSON policy was applied. Original Content-Length header was removed as its value was invalidated. Content-Type header was set to 'application/json'."

备注: 当我在 "outbound processing" 策略中应用完全相同的策略时,我得到了我期望的结果 JSON.

我发送的基本 XML 示例:

<note>
    <to>PersonOne</to>
    <from>PersonTwo</from>
    <heading>Test</heading>
    <body>Example</body>
</note>

在 "outbound policies" 部分应用策略时得到的结果(这按预期工作):

{
    "note": {
        "to": "PersonOne",
        "from": "PersonTwo",
        "heading": "Test",
        "body": "Example"
    }
}

这是由于当 APIM 将 XML 转换为 JSON 时,原来的 Content-Length header 被删除了。如果您在 APIM 中执行测试请求并查看跟踪控制台,您将看到如下消息:

"XML-to-JSON policy was applied. Original Content-Length header was removed as its value was invalidated. Content-Type header was set to 'application/json'."

A​​PIM 将 header 替换为

Transfer-Encoding: chunked

并将 Content-Length 设置为 0。不幸的是,逻辑应用程序不支持 chunked encoding on triggers (only on some actions),因此无法处理请求。