POST XML data with Groovy HTTPBuilder

buzz

New Member
I am trying to POST XML data to a URL using the HTTPBuilder class. At the moment I have:\[code\]def http = new HTTPBuilder('http://m4m:[email protected]/api/orders/create')http.request(POST, XML) {body = { element1 { subelement 'value' subsubelement { key 'value2' } } } response.success = { /* handle success*/ } response.failure = { resp, xml -> /* handle failure */ }}\[/code\]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:\[code\]<?xml version="1.0" encoding="UTF-8"?>\[/code\]which has to go at the top of the body, and secondly also the content type is not set to:\[code\]application/xml\[/code\]Then lastly, for some of the elements in the XML I need to set attributes, for example:\[code\]<element1 type="something">...</element1>\[/code\]but I have no idea how to do this in the format above. Does anyone have an idea how? Or maybe an alternative way?
 
Back
Top