使用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);
答案 0 :(得分:0)
您可以使用JObject
并从匿名对象创建string requestBodyAsJson = JObject.FromObject(new { test = string}).ToString();
:
ComponentFiles()