Unable to use CURL within GROOVY script for a REST PUT call Unable to use CURL within GROOVY script for a REST PUT call curl curl

Unable to use CURL within GROOVY script for a REST PUT call


Try using the list variation of the string and see if that works:

println ["curl", "-i", "-X PUT", "-H 'Content-Type:application/json'", "-d '{\"Key1\":1, \"Key2\":\"Value2\"}'", "http://<hostname>/foo/"].execute().text

I was having a similar problem and this was the only way I could find to solve it. Groovy will split the string into arguments at each space and I suspect this was tripping up Curl and the -H argument pair. By putting the string into the list variant, it keeps each item together as an argument.


Building on Bruce's answer, you will also need to tokenize "-X PUT". Tested out on groovy 2.3.6. ["curl", "-H", "Content-Type: application/json", "-H", "Accept: application/json", "-X", "PUT", "-d", data, uri].execute()


This works in my terminal

groovy -e "println 'curl -i -H \'Content-Type:application/json\' -XPUT -d \'{\"test\":4}\' http://google.fr/'.execute().text"

If it does not work for you, then this is likely not a groovy problem.