用restharp请求webapi

时间:2017-10-02 09:17:51

标签: c# post restsharp

Goodmorning everyone, 使用postan我如图所示发出请求,我得到数据。 我使用相同的调用(至少我假设)写,它返回一个空字符串而不是一个json。 哪里可能是错误?

谢谢大家

  var client = new RestClient("http://pp.miosito.it/API/");
            var request = new RestRequest("STHQRY", Method.POST);
            //  request.RequestFormat = DataFormat.Json;
            request.AddParameter("TblName", "STSIG$");
            var response = client.Execute(request);

            var content = response.Content;

enter image description here

1 个答案:

答案 0 :(得分:0)

添加参数中提到了查询参数详细信息。请更改以下代码

<强>代码:

    var client = new RestClient("http://pp.miosito.it/API/");
    var request = new RestRequest("STHQRY?TblName=STSIG$", Method.POST); 

    //Request Body detail needs to be added. 
    //I assumed input is JSON. Please change the header part , if the body has different
    request.AddHeader("Content-Type", "application/json");
    request.AddParameter("application/json", body, ParameterType.RequestBody);
    var response = client.Execute(request);
    var content = response.Content;