当前位置: 动力学知识库 > 问答 > 编程问答 >

use pipe for curl data

问题描述:

I'm trying to pass the cat output to curl:

$ cat file | curl --data '{"title":"mytitle","input":"-"}' http://api

But input is literally a -.

网友答案:

I spent a while trying to figure this out and got it working with the following:

cat data.json | curl -H "Content-Type: application/json" -X POST -d @- http://api
网友答案:

Try

curl --data '{"title":"mytitle","input":"'$(cat file)'-"}' http://api
网友答案:

You can use the magical stdin file /dev/stdin

cat data.json | curl -H "Content-Type: application/json" -X POST -d "$(</dev/stdin)" http://api
分享给朋友:
您可能感兴趣的文章:
随机阅读: