1

I'm trying to get a json response back from the Philips hue after I complete a PUT request. The Philips hue has a build in web server command line, when I send a basic json message like "{"on":True}" using the hue web interface I get a json response back telling me that the request was a success. The message looks like this:

"[
    {
        "success": {
            "/lights/1/state/on": true
        }
    }
]"

Right now when I send a command to the hue via my setup below, I always get a TRUE .IsSuccessStatusCode (I'm assuming becasue the message was recieved by the hue?) even if I send some json that should cause an error. Example; I could use the json {"on":Cause an error} and still get a TRUE.

So I'm trying to figure out how to get the above json response back from the hue after I've sent a PUT. Below is the code I'm using.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


    async static void setLight()
    {
        HttpClient client = new HttpClient();

        HttpRequestMessage request = new HttpRequestMessage();

        String myJson = "{\"on\":false}";

        var content = new StringContent(myJson, Encoding.UTF8, "application/json");

        HttpResponseMessage returnStatement = await client.PutAsync("http://192.168.1.3/api/139f12ce32a30c473368dbe25f6586b/lights/1/state", content);

        Console.WriteLine(returnStatement.IsSuccessStatusCode);

    }
Robomato
  • 257
  • 1
  • 2
  • 13

1 Answers1

2
 Console.WriteLine("Return Statment:" + await returnStatement.Content.ReadAsStringAsync());

This returns the json hue response I was looking for. I just kept getting basic http info back until I put the await keyword in front of it. Shout out to Q42.hueApi, I took a peak at your code and that helped greatly.

Robomato
  • 257
  • 1
  • 2
  • 13