Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl: pass a named parameter from stdin

Tags:

bash

curl

I have a web service that expects some parameters. I want to pass one of these parameters (named "data") to curl via stdin. I tried

echo -n "some data" | curl -d  x="foo" -d y="bar" -d data=@- "http://somewhere"

which doesn't work, as the value of data then is "@-" instead of "some data".

Is it possible to use the @ in curl to associate the input from stdin with a specific parameter?

edit: My goal is to chain multiples web services so the data I pass will be the output of another curl call.

like image 436
analina Avatar asked Dec 19 '22 12:12

analina


2 Answers

Use -d @-

E.g.:

echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown

Output:

<p>Hello <strong>world</strong>!</p>

Is this not possible?

curl -d  x="foo" -d y="bar" -d data="@some data" "http://somewhere"

Or

curl -d  x="foo" -d y="bar" -d data="@$(echo "some data")" "http://somewhere"

echo "some data" can be another command or file input: $(<somefile).

like image 44
konsolebox Avatar answered Jan 03 '23 06:01

konsolebox