I can control a Philips Hue light with the following command via cURL:
curl -X PUT --data '{"on":true}' "http://<bridgeip>/api/<key>/lights/7/state";
I am generating the payload with a function, so I wanted to pipe it to cURL (to take its input from stdin):
onString='{"on":true}';
echo "$onString" | curl -X PUT --data - "http://<bridgeip>/api/<key>/lights/7/state";
but this throws an error: "body contains invalid json"
What I don't get is that this works:
onString='{"on":true}';
curl -X PUT --data "$onString" "http://<bridgeip>/api/<key>/lights/7/state";
Can anyone explain please?
(Incidentally, when I pipe the output of my function to cat
the resultant string is as expected and when copied and pasted into jsonlint checks out as valid JSON.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…