gpt4 book ai didi

azure-api-management - 如何提取发送请求策略的响应状态码

转载 作者:行者123 更新时间:2023-12-05 01:43:20 34 4
gpt4 key购买 nike

使用 Azure APIM 中的发送请求策略。能够得到响应并提取Body。然而,努力提取 response.status.code

如果发送请求,这个@(context.Response.StatusCode) 的值是 200,我正在 try catch 这个值...

send-request (88 ms)
{
"response": {
"status": {
"code": 200,
"reason": "OK"
}
}
}

最佳答案

Hope below solution will work for you.

<choose>
<when condition="@(((IResponse)context.Variables["response-variable-name"]).StatusCode == 200)">
<set-variable name="xxx" value="@(((IResponse)context.Variables["response-variable-name"]).Body.As<JObject>(preserveContent: true).ToString())" />
</when>
<otherwise>
<return-response>
<set-status code="404" reason="Not Found" />
<set-body>@(((IResponse)context.Variables["response"]).Body.As<JObject>(preserveContent: true).ToString())</set-body>
</return-response>
</otherwise>
</choose>

关于azure-api-management - 如何提取发送请求策略的响应状态码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49659442/

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