Question

Hi there i am wondering how i can post a urlencoded string and read in an xml response using HTTPBuilder? I would like to use this inside a Grails application. The REST plugin is no option. I tried the examples given on http://groovy.codehaus.org/modules/http-builder/doc/post.html but this gives me no xml response to read in.

Was it helpful?

Solution

You can try something like this:

def httpBuilder = new HTTPBuilder("http://webite.url")

httpBuilder.request(Method.POST, URLENC){req->
    headers.accept = "application/xml"
    body = [ YOUR URL ENCODED POST]

    response.success = {resp,xml->
       //read xml response.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top