从 PostMan 调用 asp.net core web api

2023-12-22

我试图从 PostMan 调用以下函数(asp.net web api core):

[HttpPost]
public InfluencerSearchResultWithFacets Post(string q, string group, List<string> subGroups)
{
   return GetSearchResult("",null,null);
}

但我收到以下错误: 请求正文必须非空

I have setup PostMan like this: enter image description here

I also tried adding to body: enter image description here


所以你可以创建一个像这样的模型

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 中留下一些参数,并将其他参数作为正文传递,例如

[HttpPost]
public InfluencerSearchResultWithFacets Post([FromUri]string q, [FromUri]string group, [FromBody]List<string> subGroups)
{
   return GetSearchResult("",null,null);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 PostMan 调用 asp.net core web api 的相关文章

随机推荐