Beispiel #1
0
 /// <summary>
 /// Call to open the server and start listening for communication from IFTTT.
 /// </summary>
 public void OpenServer()
 {
     try
     {
         server      = new Crestron.SimplSharp.Net.Http.HttpServer(EthernetAdapterType.EthernetUnknownAdapter);
         server.Port = Port;
         CrestronConsole.PrintLine("IFTTT: Port #: " + Port);
         server.ServerName     = "IFTTT Server";
         server.OnHttpRequest += OnServerRequest;
         server.Open();
         CrestronConsole.PrintLine("IFTTT: Server started on port " + Port);
     }
     catch (Exception ex)
     {
         CrestronConsole.PrintLine("IFTTT: Error occurred while starting server.");
         CrestronConsole.PrintLine("IFTTT: " + ex.Message);
     }
     try
     {
         client = new HttpsClient();
         client.HostVerification = false;
         client.PeerVerification = false;
         client.KeepAlive        = false;
     }
     catch (Exception ex)
     {
         CrestronConsole.PrintLine("IFTTT: Error occurred while creating client.");
         CrestronConsole.PrintLine("IFTTT: " + ex.Message);
     }
 }
Beispiel #2
0
 public static string SecureGet(string url)
 {
     Https.HttpsClient        client  = new Https.HttpsClient();
     Https.HttpsClientRequest request = new Https.HttpsClientRequest();
     request.Url.Parse(url);
     request.RequestType = HttpsRequestType.Get;
     request.Encoding    = Encoding.ASCII;
     Https.HttpsClientResponse response = client.Dispatch(request);
     return(response.ContentString);
 }
Beispiel #3
0
 /// <summary>
 /// Call to close the server and stop listening for communication from IFTTT.
 /// </summary>
 public void CloseServer()
 {
     if (server != null)
     {
         server.Close();
         server.OnHttpRequest -= OnServerRequest;
         server.Dispose();
         server = null;
         CrestronConsole.PrintLine("IFTTT: Disposed of the server.");
     }
     if (client != null)
     {
         client.Dispose();
         client = null;
     }
 }