我在RestSharp的RestClient中使用POST方法和JSON-Patch操作(请参阅RFC:http://tools.ietf.org/html/rfc6902)时遇到问题. AddBody()包含这样的内容:
request.AddBody(new { op = "add", path = "/Resident", value = "32432" });
它出错了.我不知道如何在体内传递json-patch操作.我尽我所能.有这个问题的解决方案吗?
解决方法:
这是斯科特答案的改进版本.我不喜欢查询参数,RestSharp提供了一种直接使用AddParameter设置名称的方法
var request = new RestRequest(myEndpoint, Method.PATCH);
request.AddHeader("Content-Type", "application/json-patch+json");
request.RequestFormat = DataFormat.Json;
var body = new
{
op = "add",
path = "/Resident",
value = "32432"
}
request.AddParameter("application/json-patch+json", body, ParameterType.RequestBody);
var response = restClient.Execute(request);