use pipe for curl data

后端 未结 8 450
盖世英雄少女心
盖世英雄少女心 2020-12-23 13:26

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

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

Bu

8条回答
  •  庸人自扰
    2020-12-23 14:16

    Curl documentation for -d option

    If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with -d, --data @foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the @ character to have a special interpretation use --data-raw instead.

    Depending of your HTTP endpoint, server configuration, you should be good by using this format:

    curl -d @data.json http://api

提交回复
热议问题