Azure API Extract <send-request> 策略的响应状态代码

问题描述

我正在使用政策提出请求.. 我需要检查该请求的状态代码

我尝试使用

<choose>
  <when condition="@(((IResponse)context.Variables["LogFailedEvent"]).StatusCode != 200)">
  </when>
</choose>

甚至

<choose>
  <when condition="@(context.Response.StatusCode != 200)">
  </when>
</choose>

但它会抛出像 key not present in dictionary 这样的错误 有人有想法/解决方案吗?

解决方法

如果在您的发送请求策略中将 ignore-error 属性设置为“true”,APIM 将继续而不将响应变量设置为任何内容。使用 Azure 门户中的测试控制台跟踪您的呼叫以查看中断的位置和原因。