如何解决“curl:选项 --data-raw:未知”错误

Har*_*nan 5 shell curl sh

我正在尝试使用如下的curl命令运行shell脚本,并以--data-raw作为主体。

curl --location --request POST '<URL>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
"blocks": [
  {
 "type": "header",
 "text": {
  "type": "plain_text",
  "text": "Help Text",
  "emoji": true
 }
},
{
 "type": "divider"
},
]
}'
Run Code Online (Sandbox Code Playgroud)

输出:

curl: option --data-raw: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
Run Code Online (Sandbox Code Playgroud)

我找不到 json 验证器的任何错误。请提出一个解决方案。TIA。

Gil*_*not 13

在这里,你有两个问题。

  • 您的 JSON 无效,,需要删除第 14 行
  • 使用--data定界符
curl --location --request POST '<URL>' \
  --header 'Content-Type: application/json' \
  --data "@/dev/stdin"<<EOF
{
  "blocks": [
    {
      "type": "header",
      "text": {
        "type": "plain_text",
        "text": "Help Text",
        "emoji": true
      }
    },
    {
      "type": "divider"
    }
  ]
}
EOF
Run Code Online (Sandbox Code Playgroud)

这里的文件:

cat <<EOF后面是几行文本,后面是EOF新行上的文字字符串,不缩进。s之间的部分EOF作为标准输入传递给命令。如果'EOF'是“引用”,则不会进行替换;否则他们就是。请<<-参阅缩进品种(不推荐,需要制表符)。

  • 将“--data-raw”替换为“--data”解决了该问题。我尝试使用`&lt;&lt;EOF`,但它抛出`invalid_payloadcurl:(3) URL位置1中不匹配的大括号:{^` (2认同)