Help with body in PUT request

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:

.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:

.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

Gatling 2 syntax is different from the one in Gatling 1:

.body(StringBody("""{“test”: “test_value”}"""))

param is only for POST

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:

.queryParam(“auth”, “${token}”)

In curl command, it’d be like: curl -X PUT -L -d ““home”” “

Have you tried post instead of put?

Unfortunately the rest api that I’m testing does not support POST.

If you use triple quotes then you wont have to escape it

“”" “home” “”"



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.