[英]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: 我已经在Web api控制器中创建了一个条目,该条目可让我创建用户:
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: 现在,我想创建一个类似的条目,但是这次使用2个参数,例如:
public IHttpActionResult PutUser(int id, User user)
MY PROBLEM IS THAT I CAN'T REACH THIS METHOD WITH POSTMAN 我的问题是我无法通过邮递员达到这种方法
I already try: 我已经尝试了:
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. 这表示从请求正文接收到
user
参数。 Next, you can use the following URL: 接下来,您可以使用以下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: 为了充分利用REST,如果将
[FromUri]
添加到id
参数,并将[Route("{id}")]
到方法,则可以使用:
http://localhost:15423/api/users/5
Where 5
can be replaced by your id. 其中
5
可以替换为您的ID。
(Both requests should include the User
object in the body) (两个请求都应在正文中包含
User
对象)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.