【问题标题】:Array as parameter in GET request in Postman数组作为 Postman GET 请求中的参数
【发布时间】:2016-12-17 22:35:23
【问题描述】:

我必须在 GET 请求中发送 id 数组作为参数。如何在 Postman 中测试它(用于 API 测试的谷歌浏览器扩展)?

场景是我有网址,www.something.com/activity/poi_ids

poi_ids 应该包含像 [316,318] 这样的 id 数组

在api端使用express,

app.get('/activity/:poi_ids',function(req,res){
    var poi_ids = req.params.poi_ids;
    .......
    .......
});

I have looked into it but it is only for post request

【问题讨论】:

    标签: node.js api postman


    【解决方案1】:

    它是非结构化文本。如果您想“发送一个数组”,那么您需要设计某种方式对其进行编码,然后编写 JavaScript 对其进行解码。

    例如:

    GET /activity/316-318
    

    var poi_ids = req.params.poi_ids.split("-");
    

    【讨论】:

      【解决方案2】:

      您可以通过查询参数发送它们.. 在您的 http 查询参数中,将所有值分配给相同的变量,例如

      GET activity?pid=12&pid=23&pid=34
      

      然后在你的快递里面得到它就像

      var ids=req.query.pid; //[12,23,34]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多