I get this response: “status”: “timed_out” when using the C# HTTP client to Set State. Any ideas why this is happening? Thanks.
One more thing it seems to work fine using the older HttpWebRequest Class. But I am not able to use this class with the hardware I am writing this for. Thanks.
Nevermind I figured it out. The content portion of the Put was not being sent correctly.
How was it incorrect and how did you correct it? I seem to be having a similar issue
static async void PowerOn()
{
string selectorId = "Office";
string url = "https://api.lifx.com/v1/lights/group:" + selectorId + "/state";
string putData = "{\"power\": \"on\"}";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Application", "application/json");
client.DefaultRequestHeaders.Add("Authorization", "Bearer c8ac9827f1406f965a79");
try
{
var response = await client.PutAsync(url, new StringContent(putData, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
Console.ReadLine();
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
}
}
I deleted most of the Bearer code FYI.
The
data = “{“power”: “off”}”
fixed my problem, thanks man!