bash - curl:从标准输入传递命名参数

标签 bash curl

我有一个需要一些参数的网络服务。我想通过标准输入将这些参数之一(名为“data”)传递给 curl。 我试过了

echo -n "some data" | curl -d  x="foo" -d y="bar" -d data=@- "http://somewhere"

这是行不通的,因为 data 的值是“@-”而不是“some data”。

是否可以使用 curl 中的 @ 将来自标准输入的输入与特定参数相关联?

编辑:我的目标是链接多个网络服务,这样我传递的数据将是另一个 curl 调用的输出。

最佳答案

使用-d @-

例如:

echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown

输出:

<p>Hello <strong>world</strong>!</p>

关于bash - curl:从标准输入传递命名参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25056611/

相关文章:

java - 无法将数据发布到服务器,出现错误 java.io.IOException : Server returned HTTP response code: 415

macos - OSX 上 ffmpeg 的神秘错误

linux - 自动运行的文件

php - CURL 结果放入 PHP 数组?

php - 将 Curl 客户端 ssl 移动到 Guzzle

php - cURL 返回请启用 cookie?

bash - 在 bash 脚本中执行 gcloud 命令

linux - 在 CentOS 8 中从 pgdg 存储库安装 postgresql12-server 后找不到 pg_ctl

bash - 在 wget bash 命令中转义

java - JAX-RS 端点中的 BadRequestException