xmlgroovy

How to curl an xml in groovy?


I'm currently trying to curl an xml file through groovy:

def command = "curl -H \"Accept:  application/xml\" ${path}" 
def process = command.execute() 
process.waitFor()

When I try to execute this script, the output has no xml formatting (as in, there are no xml tags, just the contents) and I also get

curl: (6) Could not resolve host: application; Name or service not known

I tried running the same command directly in the terminal and it works fine there.


Solution

  • Replace:

    def command = "curl -H \"Accept:  application/xml\" ${path}" 
    

    With

    def command = ['curl', '-H', 'Accept:  application/xml', path]