Postman with miltiple params on Web Api C#(在 Web Api C# 上具有多个参数的邮递员)
问题描述
我对这项技术有疑问,
我已经在我的 web api 控制器中创建了一个允许我创建用户的条目:
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:
现在我想创建一个类似的条目,但这次使用 2 个参数,如下所示:
Now I want to create a similar entry but this time with 2 parameters, like this:
public IHttpActionResult PutUser(int id, User user)
我的问题是我无法通过 POSTMAN 实现此方法
我已经试过了:
- 在邮递员石南花上添加我的id"参数
- 在 postman body-form-data 上添加我的id"参数
- 在 postman body-x-www-form-urlencoded 上添加我的id"参数
- 在 json 代码前后添加我的id"参数作为分隔符 ['&', ','] 和分配字符 [':', '='].
这些都不起作用,我的想法已经用完了.
none of these worked and I ran out of ideas.
有人知道如何正确调用此服务吗?
does anyone knows how to invoke this service properly ?
最好的问候!
推荐答案
你应该给你的方法添加属性,像这样:
You should add attributes to your method, as such:
public IHttpActionResult PutUser(int id, [FromBody] User 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>
如果您将 [FromUri]
添加到 id
参数和 [Route("{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
其中 5
可以替换为您的 id.
Where 5
can be replaced by your id.
(两个请求都应在正文中包含 User
对象)
(Both requests should include the User
object in the body)
这篇关于在 Web Api C# 上具有多个参数的邮递员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Web Api C# 上具有多个参数的邮递员


- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04