Call asp.net core web api from PostMan(从 PostMan 调用 asp.net core web api)
问题描述
我正在尝试从 PostMan 调用以下函数(asp.net web api 核心):
I am trying to call following function (asp.net web api core) from PostMan:
[HttpPost]
public InfluencerSearchResultWithFacets Post(string q, string group, List<string> subGroups)
{
return GetSearchResult("",null,null);
}
但我收到以下错误:需要一个非空的请求正文
But I get following error: A non-empty request body is required
我已经像这样设置 PostMan:
I have setup PostMan like this:
我也尝试添加到正文:
推荐答案
所以你可以创建一个类似的模型
So you can create a model like
public class Model
{
public string q { get; set; }
public string group { get; set; }
public List<string>subGroups { get; set; }
}
并使用它
[HttpPost]
public InfluencerSearchResultWithFacets Post([FromBody] Model model)
{
return GetSearchResult("",null,null);
}
这是如果你适合 Json 格式.您也可以在 URL 中保留一些参数,并将其他参数作为正文传递,例如
This is if you fit Json format. Also you can leave some parameters in URL and other pass as a body like
[HttpPost]
public InfluencerSearchResultWithFacets Post([FromUri]string q, [FromUri]string group, [FromBody]List<string> subGroups)
{
return GetSearchResult("",null,null);
}
这篇关于从 PostMan 调用 asp.net core web api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 PostMan 调用 asp.net core web api


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