我需要使用c#将过滤器请求有效负载添加到Rest Post调用api。
{
"filter": {
"operator": "and",
"operands": [
{
"operator": "ne",
"value": "7",
"field": "id"
},
{
"operator": "substring",
"value": "ec",
"field": "hostName"
}
]
}
}
通过工作的Automation Anywhere API,在这里我需要发送该负载
var client= new RestClient("control room/v2/devices/list");
var restBody= new RestRequest("/", Method.POST);
restBody.AddHeader("Content-Type", "application/json");
restBody.AddHeader("X-Authorization", pAuthToken);
IRestResponse deviceListResult = client.Execute(restBody);
您将不得不为该Post方法创建一个模型,或多或少像这样:
public class GetData
{
public Filter Filter { get; set; }
}
public class Filter
{
public string Operator { get; set; }
public Operand[] Operands { get; set; }
}
public class Operand
{
public string Operator { get; set; }
public string Value { get; set; }
public string Field { get; set; }
}
并在控制器中创建一个接受该类型作为正文的Post操作:
[HttpPost]
public ActionResult([FromBody]GetData getDataRequest)
{
...
}