代码之家  ›  专栏  ›  技术社区  ›  Ashok kumar

如何对FromUri请求参数使用Postman?

  •  0
  • Ashok kumar  · 技术社区  · 6 年前

    我已经编写了下面的简单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; }
    }
    

    下面是操作的模型类:

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

    现在,我不知道如何使用Postman来检查这个Web API方法。

    我在下面试过,但没有工作。我没有收到任何错误,但我没有得到回应。有人能帮我吗?

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Alex.U    6 年前

    您在头上设置值,但在代码中使用URI。您需要更改您的代码,或者更改您向邮递员发送请求的方式。

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

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

    Have a look at this