mercredi 6 mai 2015

restsharp addparameter json For POST not work

I 'm very reading on stack overflow. But it's not work! I'm use RestSharp on REst webservice. I want to sent JSON Format to webservice.

my json fotmat, I'm sent on POSTMAN app in google chrome. It's work! :

{
"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"
}]

}

in this code:

 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();

- some one ask: request.AddParameter("application/json", json, ParameterType.RequestBody); - some one ask: request.AddObject(jsonObject) and some one ask: request.Addbody(jsonObject)

Now I'm very confused! Help me now!

P.S. if you can please revise write full my coding with me. and ask me add namespace to use. I'm add references RESTSHARP completely. P.S.1 I'm novice on c# and .net, help me now! Jesus Love You

Aucun commentaire:

Enregistrer un commentaire