I'm trying to post to Web Api Values controller via post:
// POST api/values
public void Post([FromBody]string value)
{
}
but the value is always null.
I'm using Postman to post this in body: {"test"}
set as Json(application/json)
asked Apr 13, 2017 at 19:36
-
What you are posting is not valid JSON. What it should be is {"value":"hello world"}Webbanditten– Webbanditten2017年04月13日 19:38:06 +00:00Commented Apr 13, 2017 at 19:38
-
what if it is a serialized json string? does it always have to be "value: ?BobSwanson– BobSwanson2017年04月13日 19:39:58 +00:00Commented Apr 13, 2017 at 19:39
-
No you need to create a new class which contains the properties you need and then use that as the input parameter for your "Post" Method. FromBody is really only the basic way to get simple properties - Its much easier to bind a model/class.Webbanditten– Webbanditten2017年04月13日 19:43:45 +00:00Commented Apr 13, 2017 at 19:43
-
{"value":"hello world"} still doesn't workBobSwanson– BobSwanson2017年04月13日 19:55:50 +00:00Commented Apr 13, 2017 at 19:55
1 Answer 1
Sending simply "test" in quotes did the trick.
answered Apr 13, 2017 at 20:26
Sign up to request clarification or add additional context in comments.
Comments
default