bash - cURL 命令在终端提示符下不起作用
问题描述
按照 /campaigns 下的文档,我使用我的 api-key 尝试该示例。
我在 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>" \
我将整个内容粘贴到提示中,即使这似乎不是正确的方法。
部分命令被理解,然后部分通过,shell 会问这个Display all 114 possibilities question
:
~/: curl -X POST https://api.mailerlite.com/api/v2/campaigns \
> -d '{
>
Display all 114 possibilities? (y or n)
随后是目录列表,然后是:
> 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"}}~/:
从 bash shell 发出多行 cURL 命令的正确方法是什么?
解决方案
用空格替换制表符,并删除最后一个反斜杠,那么它应该可以正常工作。
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>"
它给我以下输出:
$ 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"}}
推荐阅读
- linux - 如何让 sar 显示整个月的汇总数据?
- swift - UISlider 切换 maximumValue 和 minimumValue
- flutter - 完成后重置列表
- r - 行绑定或注释数据框,基于在列上使用之间的匹配
- spring-boot - 是否有可能从 react-native apk 访问 http 微服务?
- node.js - 如何从node js中的passportjs验证器获取数据?
- sql-server - 如何使我的日期格式如下连接 Mmm-YY SQL Server
- r - 简单的“[]”条件
- uitableview - 将 NSDiffableDataSourceSnapshot 应用于 UITableViewDiffableDataSource 导致“NSInternalInconsistencyException”
- r - 如何通过两个不同的变量创建新列?