# Gatling / Scala - Post Request: Set StringBody value from variable

**URL:** <https://community.gatling.io/t/gatling-scala-post-request-set-stringbody-value-from-variable/4377>\
**Category:** Gatling (Open-Source)\
**Created:** [June 18, 2018, 10:38pm UTC](https://community.gatling.io/t/gatling-scala-post-request-set-stringbody-value-from-variable/4377 "2018-06-18T22:38:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman.kosecky](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@roman.kosecky](https://community.gatling.io/u/roman.kosecky)\
**Post date:** [June 18, 2018, 10:38pm UTC](https://community.gatling.io/t/gatling-scala-post-request-set-stringbody-value-from-variable/4377/1 "2018-06-18T22:38:06Z")

</div>

I have the following chain:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val search= exec(repeat(products.size, "n"){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;feed(products.circular)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.uniformRandomSwitch( //5  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(session =\> {session.set("searchBody", """{"productId":"${productID}","minPrice":"${minPrice}"}""")}),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(session =\> {session.set("searchBody", """{"productId":"${productID}","category":"${category}"}""")})  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.exec(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http("/products")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.post(appURL + "/search")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.headers(jsonHeader)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.body(StringBody("${searchBody}")).asJSON  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.check(status.is(200), responseTimeInMillis.lessThan("${expectedResponseTime}"))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)  
&nbsp;&nbsp;&nbsp;&nbsp;})

I want to set into the variable searchBody the value of the body of my requests. But when I execute the requests i am getting the error:

i.g.h.a.ResponseProcessor - Request '/products' failed:status.find.is(200), but actually found 403

I think the error is how I am building the value of the body. The values of the variables are not printed in the string searchBody. Any idea?

---

<div class="post-metadata">

**Author:** ![Ethen](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@Ethen](https://community.gatling.io/u/Ethen)\
**Post date:** [June 22, 2018, 8:42am UTC](https://community.gatling.io/t/gatling-scala-post-request-set-stringbody-value-from-variable/4377/2 "2018-06-22T08:42:36Z")

</div>

[https://gatling.io/docs/current/general/debugging/](https://gatling.io/docs/current/general/debugging/)

may be helpful

在 2018年6月19日星期二 UTC+8上午6:38:06，roman…@gmail.com写道：
