gatling feeders - post does not work, get does.

I have a csv file like below.

id1,id2
123,-8
124,-9
125,-10

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
                .baseURL("http://localhost:3001/api")
                .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
                .doNotTrackHeader("1")
                .acceptLanguageHeader("en-US,en;q=0.5")
                .acceptEncodingHeader("gzip, deflate")
                .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")

  val scn = scenario("post-example")
            .feed(ids)
            .exec(http("post-example")
            .post("/create")
            .body(StringBody("""{"id1":{id1}, "id2":{id2}""")).asJSON)

  setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
}

The below one for GETs does work:

val scn = scenario("get-example")
            .feed(ids)
            .exec(http("get-example")
            .get("/someUrl")
            .queryParam("id1", "${id1}")
            .queryParam("id2", "${id2}")

Let’s play: find the differences.

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

What could be missing?

Hi,

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) {
feed(rids)
.exec(http(“post-example”)
.post("/create")
.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?