Пример #1
0
        /// <summary>
        /// Sends current set of events to BugSnag via a JSON post
        /// </summary>
        /// <param name="notification">The notification to send</param>
        /// <param name="useSSL">Indicates the post should use SSL when sending JSON data</param>
        private void SendNotification(ErrorNotification notification, bool useSSL)
        {
            string serializedJSON = notification.SerializeToString();

            //  Create a byte array:
            byte[] byteArray = Encoding.UTF8.GetBytes(serializedJSON);

            //  Post JSON to server:
            WebRequest request;

            if (useSSL)
            {
                request = WebRequest.Create(httpsUrl);
            }
            else
            {
                request = WebRequest.Create(httpUrl);
            }

            request.Method        = WebRequestMethods.Http.Post;
            request.ContentType   = "application/json";
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            //  Get the response.  See https://bugsnag.com/docs/notifier-api for response codes
            var response = request.GetResponse();
        }