TL-DnR:
curl -fG -X POST http://192.168.1.28:8060/input --data-urlencode "ala=ba&la"
Long form: I just spent significant time figuring this out, so decided to share as "recipe". TFM says that ECP /input is to be (a) POST-ed, (b) with arguments in the URL (not the body) and (c) URL-encoded. So, how do we do this from command line (mostly for dev/test/debug purposes) with CURL ?
The
input example uses -d and "cheats" on (c) by not using characters that need escaping - or ass-umes the %-encoding will be done manually by the human or extra script (ick!). Now, after some research i figured:
- curl has a way to do URL-encode with "--data-urlencode key=value"
- ... but it will send the application/x-www-form-urlencoded params in the BODY (no good for ECP!)
- ... unless you use -G, which will send the params in the URL
- ... except `curl -G -d '' ` uses GET instead of POST (-d's magic is weak, -G trumps it) and that fails with `400 Bad Request`
- ... luckily we can force it with `-X POST`
And there you have it. PITA. Bonus: use the "-f" in curl so it reports the HTTP errors.
PS. One more tip: want to "input" a multi-line value? Sure, instead of `--data-urlencode key=value` use `--data-urlencode key@myFileName` and curl will read the value from the file specified. Or substitute "-" for file name (e.g. key@-) and it will read from stdin.