HTTP POST From Cron

Hello guys,
I searched the old forum but found nothing.

To post an http command from C # program, i just type:
Net.WebService(“http://xxx.xxx.xx.xx:xxxx/api/RaspberryPi.Gpio/GPIO22/Control.Toggle”).GetData();

Please, would anyone know what is the most linear method to post the same command from Cron Java script?

Would it be possible to use JSON in your project.

Indeed,
I’m sorry, I wrote Javascript, but I meant Json… I would need to call a command via http from the Cron schedule…

Have you tried this

var postRequest = Net.WebService("/tstat")
.AddHeader(“Content-type”, “application/json”)
.Post(postString);
var postResult = postRequest.GetData();

It needs the GetData() to finally send (or Call) and get the result.

I’m testing your code by entering it in the Cron script section, but it doesn’t work for me.
I added the URL before /tstat, (inside the quotes ").
Sorry if the question is stupid, but I’m not sure if I need to add another line of code to the end of the script, or if you meant that Call with Get should be replaced by your last line of code.

This is the complete code I am testing:

var postRequest = Net.WebService(“http://xxx.xxx.xx.xx/api/HomeAutomation.HomeGenie.Automation/90/Control.ArmHome/undefined/tstat”)
.AddHeader(“Content-type”, “application/json”)
.Post(postString);
var postResult = postRequest.GetData();

(Also tested by removing /tstat from the url)

You may need to add a user name and password in that url. Try that and see if it works

Peter,
please, which user and Password are you referring to? Pi or HomeGenie?
I have no passwords set to Homegenie.
In fact typing the string on Broswer, the command is executed without a user and password request …

What result is returned from the browser request.

With the example of arming home the result is: {“ResponseValue”:“ARMING HOME”}
P.S.It work from Shell too using curl command…

Curl might be the way to go. Have a read of this from Stack Overflow. It may provide the solution for you https://stackoverflow.com/questions/7172784/how-do-i-post-json-data-with-curl-from-a-terminal-commandline-to-test-spring-res

Thank you Peter,
I’ve tried some of the solutions proposed in the link, but unfortunately they don’t seem to work in my case from Cron Script.
Waiting to find a working script, I’m trying some alternative to get around the problem.