curl脚本包括" -d"我的网址中的参数,但我不想要它

时间:2016-06-02 17:28:34

标签: bash shell curl

我在Mac Yosemite上使用bash shell。我有以下脚本......

    #!/bin/bash

    curl -u "mysecret:password!" "https://mydomein.org/myproject/oauth/token" -d 'grant_type=client_credentials'

当我运行脚本时,我收到错误

    davea$ sh curl.sh
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL /myproject/oauth/token -d was not found on this server.</p>
    <hr>
    <address>Apache/2.2.31 (Amazon) Server at mydomain.org Port 80</address>
    </body></html>
    curl: (6) Could not resolve host: grant_type=client_credentials

我不想要&#34; -d&#34;成为我的URl的一部分,这就是我在网址上加上引号的原因,但我不知道如何重写脚本以自己获取网址,然后在&#34; -d&之后发送内容#34;作为参数 ETRS。

2 个答案:

答案 0 :(得分:2)

虽然您通常会在URL之前添加选项,但curl实际上并没有坚持使用该选项。

但是,选项(通常是命令行参数)必须通过空格相互分隔,而不是空格的排版变量(em空格,非空格等)。许多文字处理器都不会插入排版符号(包括印刷报价和长划线),以使您的文件看起来更漂亮。这对于人类读者来说很酷,但它通常会混淆软件,因此在编辑shell脚本和其他程序时应避免使用这些功能。

尝试使用程序员编辑器编辑该脚本;我不知道你的Mac上可能有什么,但肯定有些东西不能修改你输入的内容。或者关闭(通常在&#34;偏好&#34;)无论正在执行什么排版替换,并使用空格和短划线重新键入该行。

答案 1 :(得分:0)

也许试试:

curl -u 'mysecret:password!' -d 'grant_type=client_credentials' 'https://mydomein.org/myproject/oauth/token'

curl - help在我的系统上直接告诉我在长帮助页面的顶部:

$ curl --help
Usage: curl [options...] <url>

所以我想当你把HTTP POST数据放在选项的位置之前,所有这些都应该能正常工作。

相关问题