Posting to a Web API using HttpClient and Web API method [FromBody] parameter ends up being null

后端 未结 1 1330
长情又很酷
长情又很酷 2020-12-14 03:27

I am attempting to POST to a Web API using the HttpClient. When I put a breakpoint in the Save method of the Web API the [FromBody] Product is null. This means that somethin

相关标签:
1条回答
  • 2020-12-14 03:54

    Have you tried inspecting the request in something like fiddler? It needs the content-type to be application/json as you have pointed out. But you are only setting the accept header.

    Try:

    StringContent content = new StringContent(JsonConvert.SerializeObject(product), Encoding.UTF8, "application/json");
    
    0 讨论(0)
提交回复
热议问题