Call asp.net core web api from PostMan

2019-07-11 19:13发布

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

I have setup PostMan like this: enter image description here

enter image description here

I also tried adding to body: enter image description here

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-11 20:06

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; }
}

and use it

[HttpPost]
public InfluencerSearchResultWithFacets Post([FromBody] Model model)
{
   return GetSearchResult("",null,null);
}

enter image description here

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);
}

enter image description here

查看更多
登录 后发表回答