protected void Page_Load(object sender, EventArgs e) { try { const string WRITEKEY = "0UKB2NF5X31UPT0C"; string strUpdateBase = "http://api.thingspeak.com/update"; string strUpdateURI = strUpdateBase + "?key=" + WRITEKEY; string strField3 = ""; if (blockValidity) { strField3 = "1"; } HttpWebRequest ThingsSpeakReq; HttpWebResponse ThingsSpeakResp; strUpdateURI += "&field3=" + strField3; ThingsSpeakReq = (HttpWebRequest)WebRequest.Create(strUpdateURI); ThingsSpeakResp = (HttpWebResponse)ThingsSpeakReq.GetResponse(); if (!(string.Equals(ThingsSpeakResp.StatusDescription, "OK"))) { Exception exData = new Exception(ThingsSpeakResp.StatusDescription); throw exData; } } catch (Exception ex) { lblError.InnerText = ex.Message; lblError.Style.Add("display", "block"); throw; } }
static void Main(string[] args) { try { //Channel 177724 const string WRITEKEY = "XXXXXXXXXXXXXXXX"; //reemplazar string strUpdateBase = "http://api.thingspeak.com/update"; string strUpdateURI = strUpdateBase + "?key=" + WRITEKEY; string strField1 = "18"; string strField2 = "42"; HttpWebRequest ThingsSpeakReq; HttpWebResponse ThingsSpeakResp; strUpdateURI += "&field1=" + strField1; strUpdateURI += "&field2=" + strField2; ThingsSpeakReq = (HttpWebRequest)WebRequest.Create(strUpdateURI); ThingsSpeakResp = (HttpWebResponse)ThingsSpeakReq.GetResponse(); if (!(string.Equals(ThingsSpeakResp.StatusDescription, "OK"))) { Console.WriteLine(ThingsSpeakResp.StatusDescription); } else { Console.WriteLine("OK"); } ThingsSpeakResp.Close(); } catch (Exception ex) { Console.WriteLine("Catch " + ex.Message.ToString()); } Console.ReadKey(); }