POST Web API method returning null

Asked

Viewed 355 times

0

I am making a Web API in C# ASP.NET and in the POST method the value is returning me null.

I’m using Postman to play a JSON within value but still returns me null.

public string Post([FromBody]string value)
{
    return value;
}

At the Postman I’m doing the following

{
    "value" : "ana"
}
  • 1

    In the method signature is waiting to receive and return a string, and you are sending an object, this could be it. I played in . Net Core here and Kestrel doesn’t even accept the request. You can use dynamic to accept objects with indefinite structure, but recommend only for study purposes or very specific cases.

1 answer

0


In Postman you must send a string and not an object.

That is, the payload must be:

"ana"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.