2014-06-08 33 views
1

我正在寻找一种方法来访问AddBody调用的序列化结果。RestSharp获取序列化输出

我使用内置的RestSharp序列化程序。 实施例:

class Foo 
{ 
    public string FooField; 
}  

void SendRecord() 
{ 

    var f = new Foo(); 
    f.FooField = "My Value"; 

    request.AddBody(f); 

    // How do I get the serialized json result of the add body call without 
    // data? I would like to log the serialized output of the add body call to 
    // the database. 
    //Expected {"FooField":"My Value"} 

    var response = client.Execute(request); 
} 
+0

请提供更多详细信息和代码示例。 – 1232133d2ffa

+0

完成。更新后... – Nikoli

回答

-1

右关闭RestSharp主页(http://restsharp.org/):

// execute the request 
RestResponse response = client.Execute(request); 
var content = response.Content; // raw content as string <~~~~~~~~~~ 
+0

这是来自服务器的响应。不是客户发送的是什么 – Nikoli

+0

我明白了。请求.Parameters.Where(p => p.Type == ParameterType.RequestBody).FirstOrDefault(); – Nikoli

1

我计算出来通过找出this post

request.Parameters.Where(p => p.Type == ParameterType.RequestBody).FirstOrDefault();