Search code examples
c#wcfhttpclientwcf-web-api

Post an empty body to REST API via HttpClient


The API I'm trying to call requires a POST with an empty body. I'm using the WCF Web API HttpClient, and I can't find the right code that will post with an empty body. I found references to some HttpContent.CreateEmpty() method, but I don't think it’s for the Web API HttpClient code since I can't seem to find that method.


Solution

  • Use StringContent or ObjectContent which derive from HttpContent or you can use null as HttpContent:

    var response = await client.PostAsync(requestUri, null);