gpt4 book ai didi

json - Azure APIM-无法访问液体模板中的 json 正文值

转载 作者:行者123 更新时间:2023-12-03 02:11:29 24 4
gpt4 key购买 nike

我正在尝试在azure中构建一个API,并尝试通过设置正文策略使用液体模板修改传入的json请求。但 json 元素为 null

传入 json 请求

{
"GetOrderDetailsResponse": {
"OrderId": 1,
"OrderDate": "2018-08-13",
"OrderLines": {
"OrderLine": [
{
"Product": "Pizza Margherita",
"Amount": 5
},
{
"Product": "Pizza Calzone",
"Amount": 2
},
{
"Product": "Pizza Funghi",
"Amount": 1
}
]
}
}
}

政策代码

<policies>
<inbound>
<base />
<return-response response-variable-name="existing response variable">
<set-status code="200" reason="OK" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">
{
"orderId" : "{{body.GetOrderDetailsResponse.OrderId}}",
"orderDate" : "{{body.GetOrderDetailsResponse.OrderDate | Date: "dd/MM/yyyy"}}",
"orderLines" : [
{% JSONArrayFor orderline in body.GetOrderDetailsResponse.OrderLines %}
{
"product" : "{{orderline.Product}}",
"amount" : "{{orderline.Amount}}"
}
{% endJSONArrayFor %}
]
}
</set-body>
</return-response>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<!--Create JSON Response via liquid template-->
</outbound>
<on-error>
<base />
</on-error>
</policies>

回复为空

{
"orderId": "",
"orderDate": "",
"orderLines": []
}

我是新手,如果我遗漏了一些明显的东西,请告知

最佳答案

正如 official docs 中所述,Content-Type header 必须设置为 application/json 才能解析正文并可用于 Liquid 模板。

在这种情况下,您可以确保发送的请求已设置,或者使用 set-header policy 在入站范围内(不在 return-response 内)手动设置它。

关于json - Azure APIM-无法访问液体模板中的 json 正文值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73262394/

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