如何将restsharp请求对象序列化为json字符串

时间:2016-08-02 15:41:29

标签: restsharp

使用restsharp调用一个restful API,这很好,但是,如何将请求对象序列化为JSON字符串,以便我可以记录发送的内容?

            var client = new RestClient("http://..."); 

            var request = new RestRequest("xxx/url", Method.POST);

            request.AddParameter("test", "string");
            request.AddParameter("test2",  "string2"); 

            IRestResponse response = client.Execute(request);

1 个答案:

答案 0 :(得分:0)

您可以使用JObject并从匿名对象创建string requestBodyAsJson = JObject.FromObject(new { test = string}).ToString();

ComponentFiles()