bash curl:没有为restful api指定URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38563589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:21:33  来源:igfitidea点击:

curl: no URL specified for restful api

bashrestcurl

提问by user6570681

I have been asked to call a restful api via Unix environment. Is there a bug in my command so i got blow issue?

我被要求通过 Unix 环境调用一个宁静的 api。我的命令中是否存在错误,因此我遇到了打击问题?

I have tried looking at the curl --help but the thing that I could find that might help would be the way to pass in param key-pair. Could it be possible to give me an example how to debug such api calling?

我曾尝试查看 curl --help 但我发现可能有帮助的方法是传入参数密钥对的方法。能否给我举个例子,如何调试这样的 api 调用?

$ curl -d param1=xxx&param2=yyy -X POST https://restful_api_path/lifecycle/v1/resource_node
[1]     10276
[2]     10277
-ksh: -X: not found [No such file or directory]
[2] +  Done                    curl -d param1=xxx&param2=yyy -X POST https://restful_api_path/lifecycle/v1/resource_node
$ curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

Cheers

干杯

回答by ipsi

You need to enclose your params in single or double quotes. e.g.

您需要将参数用单引号或双引号括起来。例如

curl -d 'param1=xxx&param2=yyy' -X POST https://restful_api_path/lifecycle/v1/resource_node

This is because the &operator in BASH is used to signify that the command should continue to run the in background, hence it must be quoted or escaped if you want a literal ampersand.

这是因为&BASH 中的运算符用于表示该命令应继续在后台运行,因此如果您想要文字与符号,则必须将其引用或转义。

回答by Kevin Li

I think you need to add double quotes to quote arguments:

我认为您需要添加双引号来引用参数:

curl -d "param1=xxx&param2=yyy" -X POST https://restfulurl/lifecycle/v1/resourcenode

P.S. On Windows you need to use double quotes, not single quotes. But in Unix, it supports both double and single quotes to quote arguments. So below cmd are fine also:

PS 在 Windows 上,您需要使用双引号,而不是单引号。但是在 Unix 中,它支持双引号和单引号来引用参数。所以下面的 cmd 也很好:

curl -d 'param1=xxx&param2=yyy' -X POST https://restfulurl/lifecycle/v1/resourcenode