我正在寻找一种方法来访问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);
}
答案 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 <~~~~~~~~~~