Issue while sending .Body(StringBody request

1,113 views
Skip to first unread message

Pritwinder saini

unread,
Mar 6, 2015, 7:37:04 AM3/6/15
to gat...@googlegroups.com
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. 

Stéphane LANDELLE

unread,
Mar 6, 2015, 7:56:37 AM3/6/15
to gat...@googlegroups.com
Where's Wally, aka "the missing double quote"?

Stéphane Landelle
Lead developer


--
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/d/optout.

Pritwinder saini

unread,
Mar 6, 2015, 8:26:06 AM3/6/15
to gat...@googlegroups.com
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

Abhinav Gogna

unread,
Mar 6, 2015, 11:45:50 AM3/6/15
to gat...@googlegroups.com
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.

Pritwinder saini

unread,
Mar 7, 2015, 1:48:33 AM3/7/15
to gat...@googlegroups.com
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"}
      1. @name"test2"
      2. @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.

Pritwinder saini

unread,
Mar 7, 2015, 6:36:29 AM3/7/15
to gat...@googlegroups.com
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 ??

Abhinav Gogna

unread,
Mar 8, 2015, 11:57:50 AM3/8/15
to gat...@googlegroups.com
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.

Stéphane LANDELLE

unread,
Mar 8, 2015, 5:38:11 PM3/8/15
to gat...@googlegroups.com
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.


    Stéphane Landelle
    Lead developer


    Reply all
    Reply to author
    Forward
    0 new messages