从 Ruby 的系统方法调用 curl 命令

Calling curl command from Ruby's system method

我在 logstash exec 插件中使用 curl 命令 post 向 stride 组发送消息。插件文档指出他们正在使用 ruby 系统方法来执行命令,所以我试图在我的 ruby IRB 中 运行 它。

使用反斜杠字符转义双引号会产生错误 The request body cannot be parsed as valid JSON。这是完整的错误

irb(main):050:0' --inf-ruby-2f3827a9-23243-13517-726000--
curl: (6) Couldn't resolve host 'first'
curl: (3) [globbing] unmatched close brace/bracket in column 9
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 165 0 87 100 78 60 54 0:00:01 0:00:01 --:--:-- 60
{
"statusCode": 400,
"message": "The request body cannot be parsed as valid JSON"
}=> true

我尝试将双引号替换为单引号并在所有地方使用完整的双引号。没有任何效果。

system("curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer blah-blah' -d '{\"body\":{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"My first message!\"}]}]}}' --url 'https://api.atlassian.com/site/blah-blah/conversation/blah-blah/message'")

有什么方法可以实现吗?

编辑: 我已经尝试 运行 在终端中使用 cURL 命令,它工作正常。

除了 Whosebug, NetHTTP has notoriously poor documentation but can be used to post what you're interested in 上的以下答案。