In my controller, I want to accept only POST variables, not the GET Variables. Grails doesn't make any distinction between POST and GET, as far as I know, though the request method can be checked via request.method, but I want to specifically only accept POST parameters. How to go about it? Sorry, if I sound too naive, I have just started groovy and grails with my background in PHP.
Asked
Active
Viewed 2,175 times
1 Answers
7
Isn't this what the allowedMethods
block is for
ie from the documentation:
class PersonController {
// action1 may be invoked via a POST
// action2 has no restrictions
// action3 may be invoked via a POST or DELETE
static allowedMethods = [action1:'POST',
action3:['POST', 'DELETE']]
def action1 = { … }
def action2 = { … }
def action3 = { … }
}

tim_yates
- 167,322
- 27
- 342
- 338
-
1Yes, but, GET parameters are also available though method allowed is only POST. That is /app/Controller/action1?a=2 still makes params.a available when the method is POST. – Nitesh Dec 05 '11 at 12:15
-
"The allowedMethods map limits access to actions based on the HTTP request method." How do you know GET parameters are there since you technically shouldn't be able to access action1 based on the above code via a GET request? – Gregg Dec 05 '11 at 15:26
-
@Gregg - You could still `POST http://example.com/person/action1?foo=bar`, and I think the OP's trying to make sure that `foo` came in within the entity instead of via query parameter. Similar to this question: http://stackoverflow.com/questions/1197729/retrieve-post-parameters-only-java – Rob Hruska Dec 05 '11 at 15:31
-
Thank you @RobHruska, that helpted, but I was wondering if some direct method was available rather than checking the queryString. Anyways thanks, I will use the solution at http://stackoverflow.com/questions/1197729/retrieve-post-parameters-only-java – Nitesh Dec 06 '11 at 05:08