有谁知道在使用
<inbound>
<base />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<return-response>
<set-status code="200" reason="OK" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">
{
"name":"{{body.firstname}}"
}
</set-body>
</return-response>
</inbound>
请求正文是:
{"firstname" : "John Doe"}`
预期结果是:
{"name":"John Doe"}
结果是:
{"name":""}
最佳答案
Microsoft 支持人员告诉我该策略 return-response
does not support set-body
与液体模板。
您可以通过在 return-response
中使用正文之前修改正文来解决此问题。
入境政策:
<inbound>
<base />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">
{
"name":"{{body.firstname}}"
}
</set-body>
<return-response>
<set-status code="200" reason="OK" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
string body = context.Request.Body.As<string>(true);
return body;
}</set-body>
</return-response>
</inbound>
请求:
POST https://rfqapiservicey27itmeb4cf7q.azure-api.net/sample/liquid HTTP/1.1
Host: rfqapiservicey27itmeb4cf7q.azure-api.net
Content-Type: application/json
{"firstname" : "John Doe"}
回应:
HTTP/1.1 200 OK
content-length: 35
content-type: application/json
date: Mon, 09 Jan 2023 04:21:51 GMT
request-context: appId=cid-v1:a10dc7c9-c354-40a2-acf3-1401681f7808
vary: Origin
{
"name": "John Doe"
}
关于azure - 液态体内返回应对政策,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75051458/