RestSharp get serialized output

好久不见. 提交于 2019-12-24 01:04:12

问题


I am looking for a way to access the serialized result of the AddBody call.

I am using the built in RestSharp Serializer. Example:

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

回答1:


I figured it out by finding this post.

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



回答2:


Right off the RestSharp homepage (http://restsharp.org/):

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


来源:https://stackoverflow.com/questions/24107747/restsharp-get-serialized-output

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