You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bruno中将字符串数组类型的customerIds参数设为外部变量?

Bruno中数组类型URL参数变量外部化解决方案

下面是几种可行的解决方法:

  • 直接用逗号分隔字符串定义变量
    在Vars标签页里,把customerIds设为逗号分隔的字符串值,比如"123,456,789",请求URL保持{{baseURL}}/endpoint?customerIds={{customerIds}}即可。绝大多数后端框架会自动将这种格式的参数解析为字符串数组。

  • 用Bruno的模板语法展开数组
    如果坚持要在Vars里定义真正的数组(比如["123","456","789"]),可以在请求URL中使用Bruno的循环模板语法来展开数组:

    {{baseURL}}/endpoint?{{#each customerIds}}customerIds={{this}}&{{/each}}
    

    注:这种写法最后会多一个&符号,多数后端会自动忽略,若要严谨可以手动去掉最后一个元素的&,或者结合预脚本处理。

  • 通过预脚本处理数组参数
    在请求的「Pre-Script」标签页中添加JavaScript代码,将数组转为符合URL要求的参数格式:

    // 从变量中获取数组
    const customerIds = vars.get('customerIds');
    // 拼接成customerIds=xxx&customerIds=xxx的格式
    const formattedParam = customerIds.map(id => `customerIds=${id}`).join('&');
    // 将处理后的字符串存入新变量
    vars.set('formattedCustomerIds', formattedParam);
    

    然后在请求URL中使用这个新变量:

    {{baseURL}}/endpoint?{{formattedCustomerIds}}
    

内容的提问来源于stack exchange,提问作者Murat K.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:12:06