Restsharp addparameter json对于POST不起作用

时间:2015-05-06 07:40:01

标签: .net json restsharp

我在REST Web服务上使用RestSharp。我想将JSON格式发送到webservice。

这是json格式,我在google chrome中使用POSTMAN测试它并且它可以工作:

{
    "boss":[{
    "cus":"454",
    "date":"July 23,2015",
    "mangpo":"9.1",
    "namo":"rattatrayaya"
    },{
    "cus":"872",
    "date":"Feb 23,2015",
    "mangpo":"9.1",
    "namo":"nama Arya Vlokita"
    }]
}

这是我的代码不起作用:

 string url = "http://ShiVamSaRaNum/Uma/index.php/create_sudo/Saranung";
        var client = new RestClient(url);
        var request = new RestRequest(Method.POST);
       request.RequestFormat = DataFormat.Json;
       request.AddBody(
           new{
               cus = "454",
               date = "July 23,2015",
               mangpo = "9.1",
               namo = "rattatrayaya"
                });
       RestResponse response = client.Execute(request);
       var content = response.Content;
       Console.WriteLine(content.ToString());
       Console.ReadLine();

我试过了:

request.AddParameter("application/json", json, ParameterType.RequestBody);
request.AddObject(jsonObject)
request.Addbody(jsonObject)

1 个答案:

答案 0 :(得分:0)

我认为request.addbody有问题我的服务器给名字老板:[{这个模式中怎么做addbody?

    "boss":[{
"cus":"454",
"date":"July 23,2015",
"mangpo":"9.1",
"namo":"rattatrayaya"
},{
"cus":"872",
"date":"Feb 23,2015",
"mangpo":"9.1",
"namo":"nama Arya Vlokita"
}]