# Issue while sending .Body(StringBody request

**URL:** <https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093>\
**Category:** Gatling (Open-Source)\
**Created:** [March 6, 2015, 12:37pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093 "2015-03-06T12:37:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pritwinder\_saini](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@Pritwinder\_saini](https://community.gatling.io/u/Pritwinder_saini)\
**Post date:** [March 6, 2015, 12:37pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/1 "2015-03-06T12:37:04Z")

</div>

I am trying to send REST POST request using .Body(StringBody however am getting 400 error

my JSON body looks like this

{  
“User”:{  
“@name”: “test3”,  
“@password”:“test1234”  
}  
}

am sending  
**.body(StringBody("""{User":{"@name":“Test3”,"@password":“test1234”}}""")).asJSON**

However am getting this error:**18:04:21.882 [WARN] i.g.h.a.AsyncHandlerActor - Request ‘request\_0’ failed: status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 400**

When I directly pass json body .body(RawFileBody(“User.json”)) it works perfectly fine.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 6, 2015, 12:56pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/2 "2015-03-06T12:56:35Z")

</div>

Where’s Wally, aka “the missing double quote”?

---

<div class="post-metadata">

**Author:** ![Pritwinder\_saini](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@Pritwinder\_saini](https://community.gatling.io/u/Pritwinder_saini)\
**Post date:** [March 6, 2015, 1:26pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/3 "2015-03-06T13:26:06Z")

</div>

that was typo  
this is request: .body(StringBody("""{“User”:{"@name":“Test3”,"@password":“Ipvs1234”}}""")).asJSON  
and error is: 18:54:24.237 [WARN] i.g.h.a.AsyncHandlerActor - Request ‘request\_0’ failed: status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 500

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [March 6, 2015, 4:45pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/4 "2015-03-06T16:45:50Z")

</div>

Status 500 is the server error. It does not look like gatling’s fault. Can you intercept your request to server using fiddler (or network tab in developer tools in chrome) and see what else is sent.

---

<div class="post-metadata">

**Author:** ![Pritwinder\_saini](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@Pritwinder\_saini](https://community.gatling.io/u/Pritwinder_saini)\
**Post date:** [March 7, 2015, 6:48am UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/5 "2015-03-07T06:48:33Z")

</div>

Am not sure how to intercept request sent from my Eclipse setup with gatling, However when I do same request from Postman or one of my tool this is how payload looks like and it works fine:

1. Request Payloadview source

Now I changed my request string to : .body(StringBody("""{User: {@name:“Test3”, @password: “Test1234”}}""")).asJSON

and same error appears: 12:08:11.016 [WARN] i.g.h.a.AsyncHandlerActor - Request ‘request\_0’ failed: status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 500

And am not convinced that its server who is culprit as sending JSON body like this .body(RawFileBody(“User.json”)) works perfectly fine.

---

<div class="post-metadata">

**Author:** ![Pritwinder\_saini](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@Pritwinder\_saini](https://community.gatling.io/u/Pritwinder_saini)\
**Post date:** [March 7, 2015, 11:36am UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/6 "2015-03-07T11:36:28Z")

</div>

Now it started working for me once i changed the request to .body(StringBody("""{User: {@name:“Test3”, @password: “Test1234”}}""")).asJSON  
I failed to notice that there was authentication which was not allowing me to have caps in name field.  
Error messages are not that elaborated to help in troubleshooting. How I can improve more helpful error messages or log when I use Gatling , Scala Ide on Eclipse Luna ??

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [March 8, 2015, 3:57pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/7 "2015-03-08T15:57:50Z")

</div>

One way to go about will be by uncommenting Trace in logback.xml as here [https://github.com/gatling/gatling/blob/master/gatling-core/src/main/resources/logback.dummy#L12](https://github.com/gatling/gatling/blob/master/gatling-core/src/main/resources/logback.dummy#L12)

And capturing responses using disableresponsechunksdiscarding function [http://gatling.io/docs/2.1.4/http/http\_protocol.html#response-chunks-discarding](http://gatling.io/docs/2.1.4/http/http_protocol.html#response-chunks-discarding). This is usually done for debugging because it hampers performance.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 8, 2015, 9:38pm UTC](https://community.gatling.io/t/issue-while-sending-body-stringbody-request/2093/8 "2015-03-08T21:38:09Z")

</div>

Still not sure about what you’re doing, as I’m not sure you provide the full working and non working sample.

Assuming that:

- body(RawFileBody(“User.json”))

- body(StringBody("""{User: {@name:“Test3”, @password: “Test1234”}}""")).asJSON

Have you considered that your issue might come from the main difference between those 2: the “asJSON” that sets the Content-Type header to “application/json”? Are you sure that your application expects this header? Sadly, even if this Content-Type value makes perfect sense, your application might expect something else.
