Regular post using ELFile

I understand that we usually use ELFilebody for parametrizing JSON/SOAP response bodies. But can we use to parametrize regular post body. I have a bunch of applications that uses same steps and branch out later. I do not wish to repeat this code again and again.

I know we can create objects and put the whole thing in there but this will make it even cleaner. Any suggestions/advise?

Sorry, I don’t get what you mean. Could you please elaborate with an example?

Here is an example of a gatling post with param:

`

.post("""/auth/kbs_logon.jsp""")
.formParam(""“auth_mode”"", “”“BASIC”"")
.formParam(""“orig_url”"", “”“null”"")
.formParam(""“retention”"", “”“null”"")
.formParam(""“aa”"", “”“AA_ALLOW”"")
.formParam(""“am”"", “”“password”"")
.formParam(""“aa_print”"", print)
.formParam(""“password”"", “${password}”))

`

instead can we do

`

.post("""/auth/kbs_logon.jsp""")
.body(ELFileBody(“login1.txt”))


`

and in login txt

CTAuthMode=BASIC&aa_param=user&aa_print=version=1&pm_fpua=mozilla/5.0 (windows nt 6.1; wow64; rv:5.0) gecko/20100101 firefox/5.0|5.0 (Windows)|Win32&pm_fpsc=24|1680|1050|1020&pm_fpsw=|pdf|qt1|qt2|qt3|qt4|qt5&pm_fptz=-5&pm_fpln=lang=en-US|syslang=|userlang=&pm_fpjv=1&pm_fpco=1 &user="${username}"

I tried this but ran into some issue. Server not processing it properly. It could be something I did wrong. Just wanted to confirm if this approach can be used.

You’re probably lack the form-url-encoded Content-Type header that’s automatically added when you use formParams.
Here, there’s nothing to tell the server that this is a form.

So I found out what was going on. Apparently when I do ELFileBody, request becomes something like:

`
stringData=…

`

whereas with formParams, I get

params=...

and server gives an error message.

Any workaround? suggestion?

Sorry forgot to mention, I am using gatling 2.0.3

stringData=… and params=… is probably something you got from the Gatling logs, right?
This is just logging, not what goes on the wire. Use something like Charles proxy.