简体   繁体   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))

The above code is used to send every circularfeeder data as a string to the body of the request.上面的代码用于将每个圆形馈送器数据作为字符串发送到请求正文。 Suppose if i want to send as byte array instead of string in the body how do I modify the line .body(StringBody("""${request}"""))假设如果我想在正文中作为字节数组而不是字符串发送我该如何修改行.body(StringBody("""${request}"""))

The code .body(ByteArrayBody(getBytesData("""${request}"""))) does not work.代码.body(ByteArrayBody(getBytesData("""${request}""")))不起作用。 Any advise?有什么建议吗?

Option 1选项1

Call getBytes method on request string and pass that to ByteArrayBodyrequest字符串调用getBytes方法并将其传递给ByteArrayBody

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

Option 2选项 2

Convert the raw data you got from your feeder.转换从馈线获得的原始数据。

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