问题描述
我在使用液体模板的 Azure API 管理中有几个操作。 几周前,我意识到现有的液体模板停止工作。
我做错了吗? API 管理有问题吗?
根据 documentation,我找不到任何错误。
因此,我创建了一个不转换请求正文的基本示例。
政策:
<policies>
<inbound>
<base />
<return-response>
<set-status code="200" reason="OK" />
<set-body template="liquid">
{
"email":"{{body.EmailAddress}}"
}
</set-body>
</return-response>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
请求:
POST https://hidden.azure-api.net/evaluation/mm/liquid HTTP/1.1
Host: hidden.azure-api.net
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
{
"EmailAddress": "sample@lorem.ipsum"
}
回复:
HTTP/1.1 200 OK
content-length: 79
date: Wed,10 Feb 2021 07:50:53 GMT
vary: Origin
{
"email":""
}
我的期望是变形的身体:
{
"email":"sample@lorem.ipsum"
}
解决方法
您是否尝试将 Content-Type: application/json
标头添加到您的请求中?
Liquid只有在设置了内容类型的情况下才有效,否则它不知道如何正确解析文档。
Microsoft 支持人员通知我,return-response 策略不支持带有 Liquid 模板的 set-body 策略。