Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The code .body(ByteArrayBody(getBytesData("""${request}"""))) does not work. Any advise?

like image 908
Harish Avatar asked Nov 28 '25 23:11

Harish


1 Answers

Option 1

Call getBytes method on request string and pass that to ByteArrayBody

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

Option 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}"))
like image 118
Camilo Silva Avatar answered Nov 30 '25 22:11

Camilo Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!