【问题标题】:Send array of guid in the parameter list of a get request using PostMan使用 PostMan 在获取请求的参数列表中发送 guid 数组
【发布时间】:2019-02-19 23:54:19
【问题描述】:

我的 api 控制器中有一个方法,它具有以下签名

[HttpGet]
[Route("api/Controller/GetResult")]
public ApiResult<List<IDocument>> GetResult(DateTime date, Guid id, List<Guid> Ids)



我需要使用 PostMan 调用它,但我不知道如何发送最后一个参数,即参数列表中的 Guid 列表,有什么帮助吗?

【问题讨论】:

    标签: api postman


    【解决方案1】:

    您可以用 JObject 替换所有参数,如下所示:

    传递 JSON:

    {"date":"2019-02-17", "id":"00000000-0000-0000-0000-000000000001", "Ids":["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]}
    

    动作:

    public ApiResult<List<IDocument>> GetResult(JObject json)
        {
            DateTime date = json.FirstOrDefault(x => x.Name == "date"))?.Value.ToString();  // simple parameter
            //----> output: "2019-02-17"
    
    
            Guid id = new Guid(json.FirstOrDefault(x => x.Name == "id"))?.Value.ToString());  // simple parameter
            //----> output: "00000000-0000-0000-0000-000000000001"
    
    
            List<JToken> Ids = json.FirstOrDefault(x => x.Name = "Ids")?.Value.ToList(); // list
            //----> output: ["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]
    
    
            //you should specify the type of "JToken" values as this:
            List<Guid> IdsList = new List<Guid>();
            foreach (var Id in Ids)
            {
                IdsList.Add(new Guid(Id.Value<string>()));
            }
        }
    

    【讨论】:

      【解决方案2】:

      您可以在内部使用邮递员Dynamic Variable$guid

      这会在运行时生成一个 v4 样式的 guid。

      使用 Postman 尝试这个 GET 请求:

      https://httpbin.org/anything?IDs=["{{$guid}}","{{$guid}}","{{$guid}}"]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-03
        • 2017-10-21
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 2014-08-17
        • 1970-01-01
        • 2019-07-07
        相关资源
        最近更新 更多