我的帖子请求如下:
POST /views/<VIEW_ID>/bulk_update.json HTTP/1.1
Host: api.abcd.com
Content-Type: application/json
Cache-Control: no-cache
发布数据:
{
"api_key":"XXXXXXXXXXXXX",
"updates":[
{"timestamp":"2018-01-31 09:25:0 -0500","value1":30},
{"timestamp":"2018-01-31 09:26:0 -0500","value1":20},
{"timestamp":"2018-01-31 09:27:0 -0500","value1":40},
{"timestamp":"2018-01-31 09:28:0 -0500","value1":70},
{"timestamp":"2018-01-31 09:29:0 -0500","value1":80},
{"timestamp":"2018-01-31 09:30:0 -0500","value1":100},
{"timestamp":"2018-01-31 09:31:0 -0500","value1":1},
{"timestamp":"2018-01-31 09:32:0 -0500","value1":11},
{"timestamp":"2018-01-31 09:33:0 -0500","value1":111},
{"timestamp":"2018-01-31 09:34:0 -0500","value1":1111},
.
.
.
.
.(total of >1000 updates)
.
.
.
.
{"timestamp":"2018-01-31 09:35:0 -0500","value1":876},
]
}
我有一个csv文件来存储所有时间戳和值。
是否有一种简单的方法可以提及所有1000个更新,而不是手动输入所有1000个更新?
这方面的任何线索都会非常有用。
答案 0 :(得分:0)
将以下代码放入“脚本”区域:
def data = new ArrayList()
1.upto(1000, {
def entry = new groovy.json.internal.LazyMap()
entry.put('timestamp', new Date().format('yyyy-MM-dd hh:mm:S ZZZZ') as String)
entry.put('value1', it)
data.add(entry)
})
def builder = new groovy.json.JsonBuilder()
builder(
api_key: "xxxxxx",
updates: data.collect {
[
timestamp: it.get('timestamp'),
value1 : it.get('value1')
]
}
)
sampler.getArguments().removeAllArguments()
sampler.setPostBodyRaw(true)
sampler.addNonEncodedArgument('',builder.toPrettyString(),'')
参考文献: