What is the ASP.NET Core equivalent to HttpRequestMessage?

Viewed 10940

I found a blog post that shows how POSTed JSON can be received as a string.

I want to know what's the new native way to do the same thing as the following code in a REST Post method in a Controller:

public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
    var jsonString = await request.Content.ReadAsStringAsync();

    // Do something with the string 

    return new HttpResponseMessage(HttpStatusCode.Created);
}

The other option bellow does not work for me, i think because I don't use Content-Type: application/json in the request header (can't change this), and I get a 415 .

public HttpResponseMessage Post([FromBody]JToken jsonbody)
{
    // Process the jsonbody 

    return new HttpResponseMessage(HttpStatusCode.Created);
}
1 Answers
Related