gatling feeders - post does not work, get does.

I have a csv file like below.


I try to use the CSV feeder to do a POST request for each of the lines in the CSV file. The POSTs don’t work. However, GETs using the same feeder file work. Is my syntax wrong? Or is it not the correct way to do POSTs using feeders?

Below is my class.

package test

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class FeederSimulation extends Simulation {

  val ids = csv("ids.csv").random

  val httpConf = http
                .acceptEncodingHeader("gzip, deflate")
                .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")

  val scn = scenario("post-example")
            .body(StringBody("""{"id1":{id1}, "id2":{id2}""")).asJSON)


The below one for GETs does work:

val scn = scenario("get-example")
            .queryParam("id1", "${id1}")
            .queryParam("id2", "${id2}")

Let’s play: find the differences.

"""{"id1":{id1}, "id2":{id2}"""

What could be missing?


Indeed, there’s a small error in your : no matter where you use EL (when it’s accepted, which is StringBody’s case), you have to use the “${…}” syntax to denote that you want to fetch data from the Session using Gatling’s EL.

Hence, your StringBody should be StringBody("""{“id1”:${id1}, “id2”:${id2}”””)

Sorry, it was just a typo in my previous thread. I indeed have the dollar…

val scn = scenario(“post-example”)
.repeat(3) {
.body(StringBody("""{“id1”:${id1}, “id2”:${id2}""")).asJSON)

is what I have…

Then, are you sure your server doesn’t expect the Content-Type header to be set to “application/x-www-form-urlencoded”?

Actually, the general issue seems to be StringBody does not work with POST.

If I replace it with RawFileBody, it works.

Yeah, it works if I use RawFileBody(“filename.json”). So don’t think its an issue with server.

I also tried passing “Content-Type” header to “application/json” in the request.

Is there any way I can console output the StringBody(…)?

Let’s play another game then:

StringBody("""{“id1”:${id1}, “id2”:${id2}""")

How many left curly braces, and how many right curly braces?