Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL config file (-k / --config) JSON newlines

I'm trying to construct a cURL config file that contains newlines in the -d/--data body but it doesn't seem to work the same as on the command line.

On the command line I can run:

curl -XPUT 'http://localhost:9200/mytype/_search' -d '{
  "query": {
    "match_all": {}
  }
}'

And the data body is correctly passed along.

However, if I try to do this in a curl -K/--config file, it doesn't work.

test.curl:

-XPUT
-d '{
  "query": {
    "match_all": {}
  }
}'

and then run curl -K test.curl 'http://localhost:9200/mytype/_search and the endpoint I submit data to fails to parse. I can make it work if I put all of the data on a single line and use double quotes, but that kills some of the legibility I'm looking for.

test2.curl works

-XPUT
-d "{\"query\": {\"match_all\": {} } }"

I have also attempted to replicate this heredoc answer: How to send line break with curl? but again it does not work in a --config file

like image 583
diplosaurus Avatar asked Nov 08 '22 06:11

diplosaurus


1 Answers

Instead of -d "{\"query\": {\"match_all\": {} } }" You can do data-binary = "@requestbody.json"

Then in requestbody.json:

{
  "query": {
    "match_all": {}
  }
}
like image 87
iEatCacti Avatar answered Nov 28 '22 02:11

iEatCacti