This is Asp.Net Webform application
This is my POST method in my Apicontroller
public void Post([FromBody]string value)
{
}
I'm with fiddler post process.
I did so experiment.
But it did not.
What is the problem.
Can you help?
I've tried it, I've failed.
public void Post(MyViewModel model)
{
string aa = model.Value;
}
public class MyViewModel
{
public string Value { get; set; }
}
In Fiddler:
Request Body:
Value=hakan
Web API reads the response body at most once, so only one parameter of an action can come from the request body. If you need to get multiple values from the request body, define a complex type. But still the value of email is NULL .
Please note that we are able to send [FromBody] parameter in HTTP GET Request input.
The [FromBody] attribute which inherits ParameterBindingAttribute class is used to populate a parameter and its properties from the body of an HTTP request. The ASP.NET runtime delegates the responsibility of reading the body to an input formatter.
[FromQuery] - Gets values from the query string. [FromRoute] - Gets values from route data. [FromForm] - Gets values from posted form fields. [FromBody] - Gets values from the request body.
The POST body payload in Fiddler should be:
=foo_bar
instead of:
value=foo_bar
That's just one of those strange things about the model binding in the Web API. If you want to support value=foo_bar
in the POST body payload you could always write a view model:
public class MyViewModel
{
public string Value { get; set; }
}
and then have your method take this view model as parameter:
public void Post(MyViewModel model)
{
... work with model.Value here as usual
}
I meet this issue, and the solution is:
to fit the Request Body format =foo_bar,
also need Request haders:
Content-Type: application/x-www-form-urlencoded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With