how to generate different request body for each request

Hi there,

I try to use following code in gatling script to generate different request body for each request, but looks like requestBody() is called once, all request share same body.
anyone know how to fix this?


def requestBody(): String = {
// return string

val submit = exec(http(“request”)

Try generating all the bodies that you want in a separate section, before the start of the http requests , and put them in a Map that you’ll transform into a feeder which you’ll use to feed the requests with.

Not sure if there are better ways but I guess that would work :slight_smile:


The right way to accomplish what you want to accomplish is to convert requestBody to return a function that takes in a Session and returns a String, like so:

def requestBody : (Session => String) = { session => /* the code that builds the string */ }


Then, every time the scenario gets to that point, it will call your function (the part on the right-side of the definition) and get a new, unique response every time.