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

如何在GET请求中传递带空方括号的参数(含示例)

在Karate中使用GET传递带空方括号的参数

针对你需要构造include[]=xxx这类带空方括号的GET参数场景,Karate里有几种简单的实现方式:

方式一:直接使用完整URL

如果参数是固定的,直接把带参数的完整URL写在Given url里即可:

Given url 'https://test.com/api/v1/account/?include[]=tickers&include[]=holdings&include[]=views'
When method get
Then status 200

方式二:用param传递数组(推荐)

Karate支持直接传递数组作为param参数,它会自动将数组格式化为key[]=value1&key[]=value2的形式,非常适合动态参数场景:

Given url 'https://test.com/api/v1/account/'
And param include = ['tickers', 'holdings', 'views']
When method get
Then status 200

方式三:手动逐个添加query参数

如果上述方式不满足需求,还可以手动重复指定同一个带[]的key,Karate会自动拼接所有对应参数:

Given url 'https://test.com/api/v1/account/'
And query include[] = 'tickers'
And query include[] = 'holdings'
And query include[] = 'views'
When method get
Then status 200

内容的提问来源于stack exchange,提问作者Holgar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 21:37:08