Azure API 管理策略:无法检查请求正文中是否存在参数

问题描述 投票:0回答:0

我有一个控制流,我在其中指定将检查请求正文中是否存在location属性的策略,如果存在,我将使用

<send-request>
发送请求这是我的代码:

<set-variable name="location-id" value="@((string)context.Request.Body.As<JObject>(preserveContent: true)["location"]["id"])" />                                                
<choose><when condition="@(!string.IsNullOrEmpty(context.Request.Body.As<JObject>(true)["location"].Value<string>()))">     
    <send-request mode="new" timeout="20" response-variable-name="locationid" ignore-error="false">
        <set-url>@($"https://api.dev.com/external/location/location/{(string)context.Variables["location-id"]}")</set-url>
        <set-method>GET</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>application/json</value>
        </set-header>
        <set-header name="Authorization" exists-action="override">
        <value>@(context.Request.Headers.GetValueOrDefault("Authorization","scheme param"))</value>
        </set-header>
        <set-body>@{ var document = (JObject)context.Variables["newRequest"];
                      return document?.ToString();
                    }</set-body>
    </send-request></when><otherwise />
这是我的请求正文:
{
"id": 0,
"policyList": [
    {
        "id": 4,
        "number": "string",
        "uri": "string"
    }
],
"primaryPolicy": {
    "id": 23,
    "number": "string",
    "uri": "string"
},
"isLocationAmountRequired": true,
"currency": 0,

"location": {
    "id": 1,
    "number": "string",
    "postcode": "string",
    "name": "string",
    "uri": "string"
},
"modifiedOn": "string",
"modifiedBy": {
    "adObjectId": "string",
    "adUserPrincipalName": "string",
    "adName": "string",
    "email": "string"
}

}

但是在这样做之后我应该得到响应但是我收到 500 内部服务器错误

{
"statusCode": 500,
"message": "Internal server error",
"activityId": "fa17a054-fbfb-477e-9637-276257808c65"
}

我该怎么做才能解决这个问题

azure azure-api-management policy
© www.soinside.com 2019 - 2024. All rights reserved.