HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: HGexperimenter on February 26, 2016, 01:26:55 AM

Title: Net.WebService and .Post for json REST request
Post by: HGexperimenter on February 26, 2016, 01:26:55 AM

Help for a newbie:
Has anyone built a program that uses Net.WebService and .Post for a json REST request?

Here is a cURL request that works: (note the escape characters for \")
curl -d "{\"tmode\":2,\"t_cool\":80}" http://<url>/tstat

Here is what I tried in HG (does not work):
string postString = "{\"tmode\":2,\"t_cool\":80}";
var resultPost = Net.WebService("<url>/tstat").Post(postString);

It does not change the thermostat and does not produce an error.
The <url> is OK because I can do a .GetData()

Thank
Title: Re: Net.WebService and .Post for json REST request
Post by: HGexperimenter on February 26, 2016, 02:05:21 AM
OK - figured it out :D

       var postRequest = Net.WebService("<url>/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.