从PostMan调用asp.net核心Web API [英] Call asp.net core web api from PostMan

查看:412
本文介绍了从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);
}

这篇关于从PostMan调用asp.net核心Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆