How to access POST body content in Grails?

I am trying to read the contents of the Grails request body and map the request to the parameters, even if I commented on grails.mime.types. I also tried setting grails.mime.types for and a blank map, and it still displays.

The body content is xml, and when Grails displays it, the key ends with "Version <? Xml". Unfortunately, the system sending the POST sets the content type to application / x-www-form-urlencoded. I have no control over their change.

I am running Grails 1.2.1.

I also tried setting format = "xml" in my UrlMappings and adding the form content type to xml mime.types, but that didn't help either. And when I try to access request.reader, it is empty.

+5
source share
2 answers

Try including 'parseRequest' in your mapping.

From docs : "Grails will not provide you with automatic XML or JSON marshaling unless you specify the parseRequest argument in the URL mapping."

0
source

If you want to access request.reader directly, instead of having the XML file not marked with a domain object, try disabling it parseRequestas follows:

class UrlMappings {

static mappings = {
    "/$controller/$action?/$id?"(parseRequest:false){
        constraints {
            // apply constraints here
        }
    }

    "/"(view:"/index")
    "500"(view:'/error')
}

}

I got this solution: http://margotskapacs.com/2013/04/request-automatic-parsing-in-grails/

0
source

All Articles