[play 1.2.5] POST request.body is null

70 views
Skip to first unread message

dao

unread,
Mar 24, 2013, 2:06:14 AM3/24/13
to play-framework
Hi,

I have a method in my controller like:

public static void tst2(@Required String deviceId, String author) {
if (validation.hasErrors()) {
error(validation.errors().get(0).message());
}
String body = IO.readContentAsString(request.body);
System.err.println(body);
renderHtml(body);
}

this method is called with POST

when I don't fill the author in my request (client side), the body is
empty. If I fill all my parameters, it is OK.
I found the workaround by adding a parameter in my declaration. But is
this a bug? is that the right workaround?

public static void tst2(@Required String deviceId, String author,
String body) {
if (validation.hasErrors()) {
error(validation.errors().get(0).message());
}
//String body = IO.readContentAsString(request.body);
System.err.println(body);
renderHtml(body);
}

Thanks

notalifeform

unread,
Mar 24, 2013, 4:36:45 PM3/24/13
to play-fr...@googlegroups.com
Hi,

I'm not sure it's a bug.. but at least is not very intuitive...

Are all parameters provided as POST parameters? or are mixing url (query) parameters with POST?

The most likely cause seems that the body of the request can only be parsed once, so if the parameters can not be extracted from the url, the body will be parsed and you can not use it anymore in your method.

Your workaround seems fine - but avoiding query params and POST params would be better.

regards,

Robert
Reply all
Reply to author
Forward
0 new messages