我的API有一个[HttpPatch]动作,我需要调用它。
[HttpPatch("{id}")]
public StatusCodeResult Patch(int id, [FromBody]JsonPatchDocument<Reservation> patch)
{
Reservation res = Get(id);
if (res != null)
{
patch.ApplyTo(res);
return Ok();
}
return NotFound();
}
我是从HttpClient类尝试它但它没有.PatchAsync()
方法?
此参数的类型为JsonPatchDocument<Reservation>
,以及如何在调用此操作时从客户端发送它?
请帮忙
你必须手动创建一个HttpRequestMessage
并通过SendAsync
发送它:
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://foo.com/api/foo"),
Method = new HttpMethod("patch"),
Content = new StringContent(json, Encoding.UTF8, "application/json-patch+json")
};
var response = await _client.SendAsync(request);