Passing body content when calling a Delete Web API method using System.Net.Http

前端 未结 3 1610
刺人心
刺人心 2020-12-20 16:36

I have a scenario where I need to call my Web API Delete method constructed like the following:

// DELETE: api/products/{id}/headers
[HttpDelete(\"{id}/heade         


        
3条回答
  •  庸人自扰
    2020-12-20 16:45

    Here is how I accomplished it

    var request = new HttpRequestMessage(HttpMethod.Delete, "http://www.example.com/");
    request.Content = new StringContent(JsonConvert.SerializeObject(object), Encoding.UTF8, "application/json");
    await this.client.SendAsync(request);
    

提交回复
热议问题