Running curl with exec.Command failed with "curl: (3) URL using bad/illegal format or missing URL"

huangapple go评论176阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月18日 13:39:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76278028.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定