In some scenarios, we must read the http request content as string, and parse the string ourselves.

public IHttpActionResult POST() 
{        
     string requestContent = ReadRequestContent(Request).Result;        
     return OK(requestContent);
}
private async Task<string> ReadRequestContentAsync(
                               HttpRequestMessage Request)
{        
     string result = await Request.Content.ReadAsStringAsync();        
     return result; 
}

 

References:

  1. https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/action-results
  2. https://weblog.west-wind.com/posts/2013/dec/13/accepting-raw-request-body-content-with-aspnet-web-api?Page=2
Advertisements