使用PostMan调用asp.net core web api

7
我正在尝试从PostMan调用以下函数(asp.net web api core):
[HttpPost]
public InfluencerSearchResultWithFacets Post(string q, string group, List<string> subGroups)
{
   return GetSearchResult("",null,null);
}

但是我收到了以下错误信息: 需要一个非空的请求体。
我已经按照以下方式设置了PostMan: 输入图像描述

enter image description here

我还尝试将以下内容添加到body中: 在此输入图片描述


3
您正在执行一个 HttpPost 请求,应该将参数放在请求体中而不是 URL 中。 - Lasse V. Karlsen
1
或者头文件... - Jasen
你也可以尝试使用[FromUri]标记你的参数。 - Lasse V. Karlsen
我尝试了所有的组合,还将参数放在了主体中。我已经添加了图片到主贴中,在30秒内完成。 - Thomas Segato
我现在尝试在所有选项卡中添加它 :D 但是当添加到正文时出现了另一个错误。值不能为空吗? - Thomas Segato
显示剩余2条评论
1个回答

8
所以您可以创建如下模型:
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);
}

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接