Issue
I 'd like to post directly a json object from a url(json) to another url
so the command goes as follows:
curl "<resource_link>.json" -o sample.json
curl -X POST "<my_link>" "Content-type: application/json" -d @sample.json
I 'd like to avoid this, so what is the solution? Is it something like that?
curl -X POST "<my_link>" "Content-type: application/json" -d "curl <resource_link>.json"
But it does not work? Also, this one post Stream cURL response to another cURL command posting the result does not explain thouroughly and it is not working Yes,
curl
manual explains the '@' but it does not explain about using another curl Alternatievely, if I could save somewhere temporarily the 1st cURL response and use it in the other command(but not in a file)
Solution
- You don't want
-x POST
in there so let's start with dropping that. - Send the results from the first transfer to stdout by not using
-o
, or telling-o
to use stdout with-o-
, and - Make sure your second transfer accepts the data to send on stdin, by using
-d@-
.
curl "<link>.json" | curl "<link2>" -H "Content-type: application/json" -d @-
With curl 7.82.0 and later
Starting with curl 7.82.0 you can do it even easier with the new --json
option:
curl "<link>.json" | curl "<link2>" --json @-
Answered By - Daniel Stenberg Answer Checked By - Robin (WPSolving Admin)