从PostMan调用asp.net核心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:
我也尝试添加到正文中:
I also tried adding to body:
答
因此您可以创建类似
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);
}