how to post plain json data to service stack rest service

雨燕双飞 提交于 2019-12-24 15:58:46

问题


Below is the code I am using to post json data to a rest ful service

var client = new JsonServiceClient(BaseUri);

        Todo d =  new Todo(){Content  = "Google",Order =1, Done = false };

        var s = JsonSerializer.SerializeToString < Todo>(d);

      //  client.Post<string>("/Todos/", "[{\"content\":\"YouTube\"}]");

     //   string payload= "[{\"id\":2,\"content\":\"abcdef\",\"order\":1,\"done\":false}]";
      //  string payload = @"{""todo"":{ {""content"":""abcdef"",""order"":1}} }";

        client.Post<string>("/todos/", s);

I tried passing plain json data , it keep on fialing with message "Bad data". Then i tried serizliing the entity that also didn't work.


回答1:


You can use PostJsonToUrl, which is included in ServiceStack.Text.



来源:https://stackoverflow.com/questions/16212129/how-to-post-plain-json-data-to-service-stack-rest-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!