Logging the XML or JSON sent by RestSharp -
i'm using restsharp send information api. log xml i've sent api can debug later.
i this:
var request = new restrequest(resourcepath, method); request.addbody(dto); logger.log(request.content); var response = client.execute(request);
but, actual request sent restsharp not seem exposed.
everything sent in request available in request.parameters.
to make getting request body easier created extension method:
public static class restsharpextensions { public static string getbody(this irestrequest request) { var bodyparameter = request.parameters .firstordefault(p => p.type == parametertype.requestbody); return bodyparameter == null ? null : bodyparameter.value.tostring(); } }
Comments
Post a Comment