如何将Postman用于FromUri请求参数?

时间:2018-08-05 10:00:40

标签: asp.net-web-api2 postman

我已经编写了以下简单的Web API方法。

[HttpGet]
[HttpPost]
public int SumNumbers([FromUri]Numbers calc, [FromUri]Operation op)
{
    int result = op.Add ? calc.First + calc.Second : calc.First - calc.Second;
    return op.Double ? result * 2 : result;
}

下面是数字的模型类:

public class Numbers
{
    public int First { get; set; }
    public int Second { get; set; }
}

下面是Operation的模型类:

public class Operation
{
    public bool Add { get; set; }
    public bool Double { get; set; }
}

现在,我不了解如何使用Postman来检查此Web API方法。

我已经尝试过如下操作,但是没有用。我没有收到任何错误,但是没有得到回应。谁能帮我吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

您要在标头上设置值,但要在代码中使用URI。您将需要更改代码或使用Postman发送请求的方式。

据我所知,您需要将值作为查询字符串的一部分添加到URI中:

http://localhost:29844/api/bindings/SumNumbers?first=10&second=20&add=true&double=false

Have a look at this

相关问题