Help with body in PUT request

1,243 views
Skip to first unread message

Yatindra AP

unread,
Jan 3, 2014, 6:47:02 PM1/3/14
to gat...@googlegroups.com
I am using version 2.0.0-M3a and I have to a web service where the a PUT request requires body data, sometimes in JSON and sometimes form URL encoded.
When I try to add .body(...) or .param(...) a compilation error occurs. Is this supported? If so what I am doing wrong from the following.

body error:
exec(http("request_1")
.put("/")
.body("""{"test": "test_value"}""")
)

04:56:14.684 [ERROR] i.g.a.ZincCompiler$ - G:\tools\gatling2\user-files\simulations\cc\PutTest.scala:27: type mismatch;
 found   : String("{\"test\": \"test_value\"}")
 required: io.gatling.http.request.Body
04:56:14.721 [ERROR] i.g.a.ZincCompiler$ -  .body("""{"test": "test_value"}""")
04:56:14.722 [ERROR] i.g.a.ZincCompiler$ -   ^
04:56:14.979 [ERROR] i.g.a.ZincCompiler$ - one error found

param error:
exec(http("request_1")
.put("/")
.param("""testparam""", """{"test": "test_value"}""")
)

05:00:00.414 [ERROR] i.g.a.ZincCompiler$ - G:\tools\gatling2\user-files\simulations\cc\PutTest.scala:27: value param is not a member of io.gatling.http.request.builder.PutHttpRequestBuilder
possible cause: maybe a semicolon is missing before `value param'?
05:00:00.417 [ERROR] i.g.a.ZincCompiler$ -  .param("""testparam""", """{"test": "test_value"}""")
05:00:00.418 [ERROR] i.g.a.ZincCompiler$ -   ^
05:00:00.502 [ERROR] i.g.a.ZincCompiler$ - one error found

Stéphane Landelle

unread,
Jan 3, 2014, 7:40:53 PM1/3/14
to gat...@googlegroups.com
Gatling 2 syntax is different from the one in Gatling 1:

exec(http("request_1")
.put("/")
.body(StringBody("""{"test": "test_value"}"""))
)

param is only for POST


2014/1/4 Yatindra AP <yatin...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lu Chen

unread,
Dec 3, 2014, 7:40:36 PM12/3/14
to gat...@googlegroups.com
I have problem when .body(StringBody("\"home\"")). In my put request, I tried to put a String wrap around double quotes in the body. But based on the extraInfo.request.getContentLength = -1, I am not sure if this is working correctly. Here's my request:

exec(http("setAway")
    .put("/structures/${structureId}/away")                                              
    .queryParam("auth", "${token}")                                                      
    .body(StringBody("\"away\""))                                                        
)

In curl command, it'd be like: curl -X PUT -L -d "\"home\"" "https://api.example.com/structures/abc/away?auth=xyz"

Abhinav Gogna

unread,
Dec 3, 2014, 8:18:54 PM12/3/14
to gat...@googlegroups.com
Have you tried post instead of put?

Lu Chen

unread,
Dec 3, 2014, 8:25:14 PM12/3/14
to gat...@googlegroups.com
Unfortunately the rest api that I'm testing does not support POST.

Abhinav Gogna

unread,
Dec 3, 2014, 8:45:09 PM12/3/14
to gat...@googlegroups.com
If you use triple quotes then you wont have to escape it

""" "home" """

Abhinav Gogna

unread,
Dec 3, 2014, 8:55:15 PM12/3/14
to gat...@googlegroups.com

Lu Chen

unread,
Dec 3, 2014, 9:19:31 PM12/3/14
to gat...@googlegroups.com
Thanks Abhinav, I just found out that my problem is related to the 307 redirect which I asked in another thread. If I just change the baseUrl to the redirected url, this actually works fine.
Reply all
Reply to author
Forward
0 new messages