Thomas Segato
Thomas Segato

Reputation: 5213

Call asp.net core web api from PostMan

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

Upvotes: 7

Views: 16259

Answers (1)

Roman Marusyk
Roman Marusyk

Reputation: 24569

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

Upvotes: 8

Related Questions