How to post an object in postman without FromBody?

Viewed 595

Let's say my controller is taking an object parameter without [FromBody], how do I post the data using Postman? I tried this way but it doesn't reach the endpoint.

enter image description here

2 Answers

I think in this case, since you're not using [fromBody] your object should be in the URL and not in the Request Body. in Postman, this can be done using the Query Params as the screenshot shows.

Yet, I don't think you could pass an object in the query params like that. I think you should instead turn it into a query string like this format

"User=abc&Pass=abc"

Multiple ways to achieve this can be found here

enter image description here

If your controller is taking an object parameter without [FromBody] then you must send the data as URL parameter:

POST http://localhost:44364/login?object={"User":"abc","Pass":"abc"}

Note: replace "object" by the name of the parameter in your controller. Also you have to know that Postman should converts special characters { " : , to %XX format and you have to manage that in your service.

If you want to send it in the body, then include [FromBody]

Related