use pipe for curl data

后端 未结 8 406
盖世英雄少女心
盖世英雄少女心 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

    0 讨论(0)
  • 2020-12-23 14:17

    This should also work

    curl -H "Content-Type: application/json" -d @data.json http://api
    

    Using -d forces curl to implicitly use POST for the request.

    0 讨论(0)
提交回复
热议问题