Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post an object in postman without FromBody?

Tags:

postman

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

like image 451
Steve Avatar asked Jul 26 '21 10:07

Steve


People also ask

How do I send raw data to my Postman?

You can use raw body data to send anything you can enter as text. Use the raw tab, and the type dropdown list to indicate the format of your data (Text, JavaScript, JSON, HTML, or XML) and Postman will enable syntax-highlighting as well as appending the relevant headers to your request.


Video Answer


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

like image 195
Ikdemm Avatar answered Oct 18 '22 12:10

Ikdemm


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]

like image 39
Jonad García San Martín Avatar answered Oct 18 '22 11:10

Jonad García San Martín