英文:
Running curl with exec.Command failed with "curl: (3) URL using bad/illegal format or missing URL"
问题
使用以下代码:
cmd := exec.Command("curl", "-F", "tarball=@"+tgzpath, "--request", "POST", "-H", fmt.Sprintf("Authorization: Bearer %s", Token), "http://localhost:1880/nodes")
但是它给出了以下错误:
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
...
相同的curl
命令在终端中正常工作:
curl -F tarball=@/tgzpath --request POST -H "Authorization: Bearer [Token]" http://localhost:1880/nodes
英文:
Using this code
cmd := exec.Command("curl", " -F", " tarball=@"+tgzpath, " --request", " POST", " -H", fmt.Sprintf("Authorization: Bearer %s", Token )," ","http://localhost:1880/nodes")
but it is giving:
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
...
The same curl
command is working fine in terminal:
curl -F tarball=@/tgzpath --request POST -H "Authorization: Bearer [Token]" http://localhost:1880/nodes
答案1
得分: 1
你应该删除参数中的所有前导空格:
cmd := exec.Command("curl", "-trace", "-F", "tarball=@"+tgzpath, "--request", "POST", "-H", fmt.Sprintf("Authorization: Bearer %s", Token), "https://httpbin.org/get/200")
请看下面 -F
和 -F
之间的区别:
$ curl " -F"
curl: (3) URL using bad/illegal format or missing URL
$ curl "-F"
curl: option -F: requires parameter
curl: try 'curl --help' or 'curl --manual' for more information
英文:
You should remove all the leading spaces in the arguments:
cmd := exec.Command("curl", "-trace", "-F", "tarball=@"+tgzpath, "--request", "POST", "-H", fmt.Sprintf("Authorization: Bearer %s", Token), "https://httpbin.org/get/200")
See the difference between -F
and -F
below:
$ curl " -F"
curl: (3) URL using bad/illegal format or missing URL
$ curl "-F"
curl: option -F: requires parameter
curl: try 'curl --help' or 'curl --manual' for more information
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论