1

我的 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>,那么在调用此操作时如何从客户端发送它?

请帮忙

4

1 回答 1

4

您必须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);
于 2018-09-17T18:55:00.657 回答