curl:从stdin传递一个命名参数

ana*_*ina 3 bash curl

我有一个需要一些参数的Web服务.我想通过stdin将这些参数之一(名为"data")传递给curl.我试过了

echo -n "some data" | curl -d  x="foo" -d y="bar" -d data=@- "http://somewhere"
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为数据的值是"@ - "而不是"某些数据".

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

编辑:我的目标是链接多个Web服务,以便我传递的数据将是另一个curl调用的输出.

Cir*_*四事件 7

使用-d @-,而不是 -d @-.例如:

echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown
Run Code Online (Sandbox Code Playgroud)

输出:

<p>Hello <strong>world</strong>!</p>
Run Code Online (Sandbox Code Playgroud)


kon*_*box 1

这不可能吗?

curl -d  x="foo" -d y="bar" -d data="@some data" "http://somewhere"
Run Code Online (Sandbox Code Playgroud)

或者

curl -d  x="foo" -d y="bar" -d data="@$(echo "some data")" "http://somewhere"
Run Code Online (Sandbox Code Playgroud)

echo "some data"可以是另一个命令或文件输入:$(<somefile).