I am trying to execute a simple PUT request using CURL. It just resides on the terminal, but cannot make it work in my Groovy script.
Here is a fragment of it: -
class Test { //Throws 415 Cannot Consume Content Type void testPUT () { println "curl -i -X PUT -H \"Content-Type: application/json\" -d '{\"Key1\":1, \"Key2\":\"Value2\"}' http://<hostname>/foo/".execute().text } // Works Perfectly Fine void testGET () { println "curl -i -X GET -H \"Content-Type: application/json\" http://<hostname>/foo".execute().text } }
I also tried to enclose the command using triple quotes like: -
"""curl -i -X PUT -H "Content-Type:application/json" -d '{"Key1":1,"Key2":"Value2"}' http://<hostname>/foo""".execute().text
All my attempts just give 415 Content type cannot be consumed
When I just use the curl command in the terminal window, both the PUT and GET methods work fine.
Am I missing something? Any help would be appreciated!
Thanks!
source share