简体   繁体   中英

Postman with miltiple params on Web Api C#

I'm having a problem with this technology,

I already have created a entry in my web api controller that allows me to create users:

public IHttpActionResult PostUser(User user)

and I can consume this rest service with postman like this:

使用邮递员张贴

Now I want to create a similar entry but this time with 2 parameters, like this:

        public IHttpActionResult PutUser(int id, User user)

MY PROBLEM IS THAT I CAN'T REACH THIS METHOD WITH POSTMAN

I already try:

  • Add my "id" parameter on postman heather
  • Add my "id" parameter on postman body-form-data
  • Add my "id" parameter on postman body-x-www-form-urlencoded
  • Add my "id" parameter on postman body-raw befor and after the json code using as separator ['&' , ','] and as asignation char [':', '='].

none of these worked and I ran out of ideas.

does anyone knows how to invoke this service properly ?

best regards!

You should add attributes to your method, as such:

public IHttpActionResult PutUser(int id, [FromBody] User user)

This indicates the user parameter is received from the request body. Next, you can use the following URL:

http://localhost:15423/api/users?id=<your_id>

And in favor of full on REST use, if you add [FromUri] to the id parameter, and a [Route("{id}")] to the method, you could use:

http://localhost:15423/api/users/5

Where 5 can be replaced by your id.

(Both requests should include the User object in the body)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM