I am trying to check if a param exists in the body of the POST request. But i get the following error :
{
"messages": [
{
"message": "Expression evaluation failed.",
"expression": "(string)context.Variables[\"param1\"] != null || ((string)context.Variables[\"param2\"] != null) || ((string)context.Variables[\"param3\"] != null) || ((string)context.Variables[\"param4\"] != null)",
"details": "Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'System.String'."
},
"Expression evaluation failed. Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'System.String'.",
"Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'System.String'."
]
}
I define values like this :
<set-variable name="param1" value="@(context.Request.Body.As<JValue>(preserveContent: true).GetValueOrDefault("param1", null))" />
<set-variable name="param2" value="@(context.Request.Body.As<JValue>(preserveContent: true).GetValueOrDefault("param2", null))" />
<set-variable name="param3" value="@(context.Request.Body.As<JValue>(preserveContent: true).GetValueOrDefault("param3", null))" />
<set-variable name="param4" value="@(context.Request.Body.As<JValue>(preserveContent: true).GetValueOrDefault("param4", null))" />
This is my test code :
<when condition="@((string)context.Variables["param"] != null || ((string)context.Variables["param2"] != null)
|| ((string)context.Variables["param3"] != null) || ((string)context.Variables["param4"] != null))">
...
</when>
This is what I send in the post body :
{"param2":false}
I also tried with
context.Request.Body.As<JObject>
but I got the same error.
And also with just :
<set-variable name="param1" value="@(context.Request.Body.As<JObject>(preserveContent: true).GetValue("param1"))" />
What should I do?

