Issue while sending .Body(StringBody request

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.

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

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

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.

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

    {User: {@name: “test2”, @password: “Test1234”}}

    1. User: {@name: “test2”, @password: “Test1234”}
    2. @name: “test2”
    3. @password: “Test1234”

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.

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 ??

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

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

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.