繁体   English   中英

Gatling 请求正文作为字节数组

[英]Gatling request body as bytearray

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}"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM