Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null value when Pass values [FromBody] to post method by Postman plugin [duplicate]

I use api controller in ASP.net web API and i need to pass value to post method by [FromBody] type..

 [HttpPost]  public HttpResponseMessage Post( [FromBody]string name)  {      ....  } 

i use Postman plugin but when send to post method value of name always is null.. follow this image: enter image description here

and in Post methods : enter image description here

why this happend?!

like image 966
Saeed Ahmadian Masal Avatar asked Apr 30 '17 07:04

Saeed Ahmadian Masal


People also ask

Why your Frombody parameter is always null?

If you need to get multiple values from the request body, define a complex type. But still the value of email is NULL . The JavaScript code is part of generic method we use, so that's why the content-type is set to application/json; charset=utf-8 .

How do you pass string parameters in Postman?

Right-click selected text, and choose EncodeURIComponent to manually encode a parameter value. To send a path parameter, enter the parameter name into the URL field, after a colon, for example :id . When you enter a path parameter, Postman will populate it in the Params tab, where you can also edit it.

How do I pass a null parameter in Web API?

Simply add parameterName = null in your route parameter. Another option is add an overload. Have 2 function names receive different parameters. @kanika it's a precaution because there might be something yet to be setup in your controller and your controller is not accepting the parameters being sent.


1 Answers

Post the string with raw json, and do not forget the double quotation marks.

enter image description here

like image 92
Feiyu Zhou Avatar answered Oct 13 '22 00:10

Feiyu Zhou