Unable to post request body

55 views
Skip to first unread message

Anuja Kadloor

unread,
Aug 19, 2016, 7:35:29 AM8/19/16
to Gatling User Group
Hi Stephanie,

I'm trying to post a request along with JSON body using gatling. However, the body is not getting attached with request.
I know this for sure because expected response with request body and without it is different. 
Here is my code:-

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL(url)
.inferHtmlResources()

val headers_0 = Map("Origin" -> "chrome-extension://aejoelaoggembcahagimdiliamlcdmfm")

val uri1 = "abc.com"

val scn = scenario("RecordedSimulation")
.exec(http("request_0")
.post("/abc/efg")
.headers(headers_0)
.body(RawFileBody("RecordedSimulation_0000_request.txt"))
.basicAuth("uid","pwd")
.check(bodyString.is(RawFileBody("RecordedSimulation_0000_response.txt"))))

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

RecordedSimulation_0000_request.txt file consists of JSON content.

Request you to kindly suggest me a solution at the earliest.

PS:- I have tried using .asJSON as well after body eg. - body(RawFileBody("RecordedSimulation_0000_request.txt")).asJSON
 but still not getting the response as expected.

Thanks,
Anuja


Anuja Kadloor

unread,
Aug 22, 2016, 10:29:41 AM8/22/16
to Gatling User Group
Hi All,

Any help would be highly appreciated.

Thanks,
Anuja

Vrushalee Ajotikar

unread,
Aug 23, 2016, 7:31:35 AM8/23/16
to Gatling User Group
Hi Anuja,

You have used bodyString.is(RawFileBody("RecordedSimulation_0000_response.txt").  I had the same case and I used JSON file instead of text.

Here is my code

            exec(http("Query (direct)...")
              .postnode)
                .body(ELFileBody("payloads/elastic_search_query.json")).asJSON

Thanks,
Vrushalee Ajotikar

CyberNinja

unread,
Aug 24, 2016, 10:17:37 PM8/24/16
to Gatling User Group
Correction: ELFileBody --> ElFileBody

(L is lowercase in El)
Reply all
Reply to author
Forward
0 new messages