RestSharp获得序列化输出

时间:2014-06-08 15:32:48

标签: c# restsharp

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

我正在使用内置的RestSharp Serializer。 示例:

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

2 个答案:

答案 0 :(得分:1)

我通过找到this post来解决这个问题。

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

答案 1 :(得分:-1)

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

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