通过 curl 发送到 Discord API 的 json 中的变量插入。 "unmatched close brace/bracket in URL position X"



我在向Discord发送curl请求时遇到了一个小问题。

我的脚本:

#!/bin/bash
discord_webhook="https://discord.com/api/webhooks/ID/XXXXX"
tmp_file=/tmp/toblock.tmp
blocked_ip=$(paste -s -d ' ' $tmp_file)
if ! [ -z "$discord_webhook" ]; then
curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'$blocked_ip'"}]}' "$discord_webhook"
fi

/tmp/toblock.tmp的内容是以下两行(测试随机ip(:

15.15.15.15
16.16.16.16

错误是

root@vm1 ~ # bash ad.sh
curl: (3) unmatched close brace/bracket in URL position 13:
16.16.16.16"}]}
^

有人能看到我的冰壶请求中的错误在哪里吗?

$blocked_ip包含空格,因此将JSON拆分为多个参数。你需要把它放在双引号中以防止这种情况发生。

curl -H "Content-Type: application/json" -d '{"username": "IP blocking", "embeds":[{"title":"New IP(s) blocked","description":"'"$blocked_ip"'"}]}' "$discord_webhook"

相关内容

最新更新