Postman with miltiple params on Web Api C#

前端 未结 1 1440
离开以前
离开以前 2021-01-24 11:46

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 IHttpActionR         


        
1条回答
  •  时光取名叫无心
    2021-01-24 11:49

    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=
    

    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)

    0 讨论(0)
提交回复
热议问题