Exemplo n.º 1
0
        protected bool PostRequest(string url, JointSpaceKey key)
        {
            try
            {
                Log.Debug("Auto3D: PostRequest to URL = \"" + url + "\"");

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                request.Timeout     = 3000;
                request.ContentType = ContentType;
                request.Method      = "POST";

                var jsonString = JsonConvert.SerializeObject(key, Formatting.None);
                Log.Debug("Auto3D: JSON-String = \"" + jsonString + "\"");

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    streamWriter.Write(jsonString);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                Application.DoEvents();
                Thread.Sleep(50);

                using (var httpResponse = (HttpWebResponse)request.GetResponse())
                {
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                        Log.Debug(result);
                    }
                }

                Application.DoEvents();
            }
            catch (Exception ex)
            {
                Log.Info("Auto3D: PostRequest: " + ex.Message);
                Auto3DHelpers.ShowAuto3DMessage("Command to TV could not be sent: " + ex.Message, false, 0);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        protected bool PostRequest(string url, JointSpaceKey key)
        {
            try
            {
                Log.Debug("Auto3D: PostRequest to URL = \"" + url + "\"");

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                request.Timeout = 3000;
                request.ContentType = ContentType;
                request.Method = "POST";

                var jsonString = JsonConvert.SerializeObject(key, Formatting.Indented);
                Log.Debug("Auto3D: JSON-String = \"" + jsonString + "\"");

                using (var streamWriter = new StreamWriter(request.GetRequestStream(), Encoding.UTF8))
                {
                    streamWriter.Write(jsonString);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                Application.DoEvents();
                Thread.Sleep(50);

                using (var httpResponse = (HttpWebResponse)request.GetResponse())
                {
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                        Log.Debug(result);
                    }
                }

                Application.DoEvents();
            }
            catch (Exception ex)
            {
                Log.Info("Auto3D: PostRequest: " + ex.Message);
                Auto3DHelpers.ShowAuto3DMessage("Command to TV could not be sent: " + ex.Message, false, 0);
                return false;
            }

            return true;
        }