Harish
Harish

Reputation: 613

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?

Upvotes: 3

Views: 1951

Answers (1)

Camilo Silva
Camilo Silva

Reputation: 8711

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

Upvotes: 2

Related Questions