欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Http接口post类型中request body的row中传参调用

程序员文章站 2022-03-20 08:23:59
...

Postman中调用如下
Http接口post类型中request body的row中传参调用
Restsharp 调用

  
  public static void RestSharpRun()
  {
      RestClient client = new RestClient("http://InterfaceUrl")        
      {
          Timeout = 600000
      }
      RestRequest request = new RestRequest("yourMethod",Method.POST);
      request.AddHeader("xxx", "xxx");

      Params paramModel = new Params
      {
          iMethodName = "xxxx",
          startFltDatePek = "2020-01-10 15:45:26",
          endFltDatePek = "2020-01-11 15:45:26"
      };
      string jsonPar = JsonConvert.SerializeObject(paramModel);
      request.AddJsonBody(jsonPar);  //参数在request body 的row中
      
      var content = client.Execute(request).Content;
      if (!string.IsNullOrEmpty(content))
      {
          T result = JsonConvert.DeserializeObject<T>(content);
          if (result.Body != null)
          {
              // 处理result.Body
          }
      }
  }
END