Trying to use C#

I’m not sure where I am wrong, but there aren’t very many examples
string Xml = null;
string path = “https://api.lifx.com/v1/lights/all/state”;
//string selector = “group: Family Room”;
string uri = null;
string header = “Header = [CENSORED]”;
string output = “{power: on}”;
//bool success3 = _core.ApiApp().SetDiagOutput("URI= Went to Pre ");
//uri = path + selector + output;
//bool success2 = _core.ApiApp().SetDiagOutput("URI= " + uri);
//System.Diagnostics.Process.Start(uri);
HttpWebRequest httpWebRequest = null;
HttpWebResponse response = null;
string webAddr = path;
httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = “application/json; charset=utf-8”;
httpWebRequest.Method = “PUT”;

        using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            //string json = "{\"all\"}" + "," + "{\"power\":\"off\"}";
            string json = "{\"power\": \"on\", \"color\": \"blue saturation:0.5\", \"brightness\": 0.5, \"duration\": 5}";

            streamWriter.Write(header);
            streamWriter.Write(path);                     
            streamWriter.Write(json);
            streamWriter.Flush();
        }
        HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            string result = streamReader.ReadToEnd();
            //return result;
        }

Edit by @daniel_hall: Removed token from script, moved to the right topic.

First off, you’ll need to go and revoke that token from your account, anyone who has seen it in the past two days here on the forums now has control over your bulbs.

My .NET is very rusty, the last time I did it was for a Uni assignment so I’m not sure the reason for using System.Net.WebRequest, however it is much simpler if you use System.Net.WebClient instead. Here is my example code:

string token = "[YOUR TOKEN GOES HERE]";

WebClient client = new WebClient();
client.Headers.Add("authorization", "Bearer " + token);
string url = "https://api.lifx.com/v1/lights/location:Work/state";
string data = "{\"power\": \"off\"}";
client.UploadData(url, "PUT", Encoding.UTF8.GetBytes(data));

Thanks, Daniel. Yeah, I realized about the token right away and revoked it. I’ve got everything working now. Thanks, again.

Regards,
Brian Garr561.271.4750