Curl returns Bad Request - Invalid Header (OK in terminal)

I am struggling with curl again…

I can make my curl script run just fine on Windows (cygwin64), OSX, and Raspbian (through ssh). However no version of what I use (escaped symbols or otherwise) will work with openHAB2.

Does work in Windows/OSX/Raspbian:

curl -X POST -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer www-www-www-www” -d “” “

Does NOT work in OH2:

curl -X POST -H \"Content-Type: application/json; charset=utf-8\" -H \"Authorization: bearer www-www-www-www\" -d \"\" \"\"


rule "wireless curl execution"
Time cron "0 */5 * * * ?"
val String results = executeCommandLine(“curl -X POST -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer www-www-www-www” -d “” “””, 5000)
logInfo(“Curl”, results)



2016-09-27 10:50:01.018 [INFO ] [.eclipse.smarthome.model.script.Curl] -
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
100 339 100 339 0 0 374 0 --:–:-- --:–:-- --:–:-- 374

Bad Request

Bad Request - Invalid Header

HTTP Error 400. The request has an invalid header name.


I’ve tried escaping, not escaping, using @@ instead of spaces, rearranging the order of the headers, different encoding, different content types, but nothing I do returns the same result as it does via terminal/ssh/cygwin/cmd.

These variations also work in a terminal, but not in OH2 (when escaped):

curl -X POST -H “host:” -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer www-www-www-www” -d “” ""
curl -X POST -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer www-www-www-www” -d “” “


When at first I don’t succeed, put it in a script and have OH call the script.

There are so many variables of things that could be wrong I’ve given up trying to figure them out.

I’ve tried in a bash script and it still fails so might have to try something else but that requires learning how. I’ll have a play looking for tutorials online.

Is there a language that works better than any other for OH? PHP? Python?

Not that I know of. All languages are capable of doing this. However, if it doesn’t work from curl within a shell script when called by OH, I don’t think writing another program is going to fix the root of the problem which is why it behaves different when called from OH verses the command line.

Hmm, OK.

Not sure how to proceed then. If it works from command line, but not from OH via any kind of method, would it be safe to assume that something in karaf/osgi parses a curl differently?

More likely there is something odd with the openhab user and its ability to run curl. Have you tried running the curl as the openhab user?

sudo -u openhab curl...

That works fine via console, too. I’ll investigate my openhab user a bit more.

A similar problem with curl…
Who could understand why in the terminal works, but does not work in the EXEC bindings?