Send 2 or more Raw Body Parameters Post Request with Postman
I found that it's just one [FromBody]
is allowed in API, and that makes sense. So probably the answer is: There is no way to have 2 or more parameters with [FromBody]
attribute.
Saeid
Updated on August 16, 2022Comments
-
Saeid over 1 year
I have an ASP.NET Core 2.0 API Method:
[HttpPost("api/days")] GetDays([FromBody] DateTime startTime, [FromBody]DateTime endTime) { }
And I tried to send a Post request with Postman, but there is a problem, the parameters always have default values.
Here is my Post request looks like:
Result: Not Worked; Both parameters in API method get the default values.
If I change my API params to:
[HttpPost("api/days")] GetDays([FromBody] Inputparam param) { } public class Inputparam { public DateTime startTime { get; set; } public DateTime endTime { get; set; } }
That's worked perfectly!
But I wanna to send parameters directly and not inside wrapper object.
So, I came back with first API method and then I tried:
Result: Not Worked; Both parameters in API method get the default values.
And This one:
Result: Not Worked perfectly; Just first parameter (startTime) set it and second parameter still have default value.
And This one:
Result: Not Worked; Both parameters in API method get the default values.
I also tried
[FromForm]
instead of[FromBody]
in API, nothings changed.If I don't use
[FromBody]
in api and send the request viax-www-form-urlencoded
that's worked perfectly.But I need send a raw body with JSon.
How could I sent 2 different parameters as a raw body json?
Any idea? Where is the problem?
-
Saeid almost 6 yearsIt's not Post By Raw Body