加特林请求正文作为字节数组


val scn = scenario("gatling test").
feed(circularfeeder.circular)
.exec(http("request")
.post(endpoint)
.header("Content-Type", "application/json")
.header("Accept-Encoding", "charset=UTF-8")
.body(StringBody("""${request}"""))
.check(status.is(200))

上面的代码用于将每个循环馈送器数据作为字符串发送到请求正文。假设如果我想在正文中以字节数组而不是字符串的形式发送,如何修改行.body(StringBody("""${request}"""))

代码.body(ByteArrayBody(getBytesData("""${request}""")))不起作用。有什么建议吗?

选项 1

request字符串上调用getBytes方法并将其传递给ByteArrayBody

.body(ByteArrayBody { session => 
session("request")
.validate[String]
.map(s => s.getBytes(StandardCharsets.UTF_8)) 
})

选项 2

转换从馈纸器获得的原始数据。

val circularfeeder = csv("myFile.csv").convert {
case ("request", string) => string.getBytes(StandardCharsets.UTF_8)
}
...
.body(ByteArrayBody("${request}"))

最新更新