I am trying to POST XML data to a URL using the HTTPBuilder class. At the moment I have:
def http = new HTTPBuilder('http://m4m:aghae7eihuph@m4m.fetchapp.com/api/orders/create')
http.request(POST, XML) {
body = {
element1 {
subelement 'value'
subsubelement {
key 'value2'
}
}
}
response.success = { /* handle success*/ }
response.failure = { resp, xml -> /* handle failure */ }
}
and upon inspection I see that the request does get made with the XML as the body. I have 3 issues with this though. The first is, it omits the classic xml line:
<?xml version="1.0" encoding="UTF-8"?>
which has to go at the top of the body, and secondly also the content type is not set to:
application/xml
Then lastly, for some of the elements in the XML I need to set attributes, for example:
<element1 type="something">...</element1>
but I have no idea how to do this in the format above. Does anyone have an idea how? Or maybe an alternative way?