user6251216 user6251216 - 1 year ago 106
ASP.NET (C#) Question

ASP .NET Web API - Get plain json in POST method

I have a Web API controller that has a POST method which receives data from the request body, and all it does is send it to another web service, so deserializing the data is not necessary. How can I disable the auto deserialization done by the Web API?

public IHttpActionResult Post([FromBody]string data)
//Post with http client...


The data arrives as null with this signature.

Answer Source

Check this:

public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
    var data = await request.Content.ReadAsStringAsync();
    // do stuff with the content

More about the solution:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download