more G-Labs products

Author Topic: Net.WebService and .Post for json REST request  (Read 1003 times)

February 26, 2016, 01:26:55 AM
Read 1003 times

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42

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

February 26, 2016, 02:05:21 AM
Reply #1

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
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.