我试图使用CURL做一个简单的PUT请求.很简单,它在终端上但无法在我的Groovy脚本中运行.
这是它的片段: -
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
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试使用三重引号括起命令,如: -
"""curl -i -X PUT -H "Content-Type:application/json" -d '{"Key1":1,"Key2":"Value2"}' http://<hostname>/foo""".execute().text
Run Code Online (Sandbox Code Playgroud)
我所有的尝试只是给出了415内容类型无法消费
当我在终端窗口上使用curl命令时,PUT和GET方法都可以正常工作.
我错过了什么吗?任何帮助,将不胜感激!
谢谢!