简体   繁体   English

cURL 命令在终端提示符下不起作用

[英]cURL command doesn't work from terminal prompt

Following the documentation here under /campaigns I try the example with my api-key.按照 /campaigns 下的文档我尝试使用我的 api-key 示例。

I am using the terminal window on a Mac (bash shell).我在 Mac(bash shell)上使用终端窗口。

curl -X POST https://api.mailerlite.com/api/v2/campaigns \
-d '{
        "subject": "Regular campaign subject",
    "segments": 1291259,
    "type": "regular"
}' \
-H "Content-Type: application/json" \
-H "X-MailerLite-ApiKey: <api-key>" \

I paste this whole thing into the prompt even though that doesn't seem the correct way to do this.我将整个内容粘贴到提示中,即使这似乎不是正确的方法。

Part of the command is understood and then part way through, the shell asks this Display all 114 possibilities question :部分命令被理解,然后部分通过,shell 会询问这个Display all 114 possibilities question

~/: curl -X POST https://api.mailerlite.com/api/v2/campaigns \
> -d '{
> 
Display all 114 possibilities? (y or n)

Followed by a directory listing, Followed by:后跟目录列表,后跟:

> campaign subject",
>     "segments": 1291259,
>     "type": "regular"
> }' \
> -H "Content-Type: application/json" \
> -H "X-MailerLite-ApiKey: <api-key>" \
> 
{"error":{"code":400,"message":"Campaign type is missing"}}~/: 

What is the proper way to issue a multi-line cURL command from a bash shell?从 bash shell 发出多行 cURL 命令的正确方法是什么?

Replace tabs with spaces, and drop the last backslash, then it should work just fine.用空格替换制表符,并删除最后一个反斜杠,然后它应该可以正常工作。

curl -X POST https://api.mailerlite.com/api/v2/campaigns \
-d '{
    "subject": "Regular campaign subject",
    "segments": 1291259,
    "type": "regular"
}' \
-H "Content-Type: application/json" \
-H "X-MailerLite-ApiKey: <api-key>"

It gives the following output to me:它给了我以下输出:

$ curl -X POST https://api.mailerlite.com/api/v2/campaigns \
> -d '{
>     "subject": "Regular campaign subject",
>     "segments": 1291259,
>     "type": "regular"
> }' \
> -H "Content-Type: application/json" \
> -H "X-MailerLite-ApiKey: <api-key>"
{"campaign_type":"regular","date":"2020-10-06 19:21:47","account_id":<id>,"id":<id>,"mail_id":<id>,"options":{"current_step":"step3","send_type":"regular","campaign_type":"regular","date":"2020-10-06 19:21:47"}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM