Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a post request with parameter?

I created a WebAPI with Visual Studio 2017 using its .Net Core template. I am able to test my Get() code with Postman and everything works correctly. Now, I would like to send a Post request so it calls the following code.

[HttpPost]
public void Post([FromBody] string value)
{
  Console.WriteLine("value" + value);
}

However, I get the following error when call

https://localhost:44364/api/carbon?value=100

{
    "": [
        "A non-empty request body is required."
    ]
}

I am sure the problem lies with they way my Postman is setup but it looks correct.

enter image description here

Any suggestions? Thank you!

Updated per suggestion

I added key/value to the body and received "The input was not valid."

enter image description here enter image description here

like image 285
PKonstant Avatar asked Jan 27 '26 10:01

PKonstant


1 Answers

You do not need to use Query string.You need to post the string with raw json, and do not forget the double quotation marks.Refer to here to get more details on post methods by Postman. enter image description here

like image 56
Ryan Avatar answered Jan 28 '26 23:01

Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!