Exemplo n.º 1
0
        private static HttpWebRequest sendData(Mmonit_T config, string D)
        {
            // http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx
            // send to mmonit
            var request = (HttpWebRequest)WebRequest.Create(config.url.url);

            AddBasicAuthHeaderMonit(config, request);

            request.Headers.Add("Pragma", "no-cache");
            request.UserAgent = string.Format("Monit/{0}", MonitWindowsAgent.VERSION);
            request.Accept    = "*/*";

            request.Method      = "POST";
            request.ContentType = "text/xml";

            var encoding = Encoding.GetEncoding("ISO-8859-1");
            var byteData = encoding.GetBytes(D);

            request.ContentLength = byteData.Length;

            try
            {
                using (var reqStream = request.GetRequestStream())
                {
                    reqStream.Write(byteData, 0, byteData.Length);
                }
                Logger.Log.Debug("Sent to mmonit: " + D);
                return(request);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 private static void AddBasicAuthHeaderMonit(Mmonit_T config, HttpWebRequest request)
 {
     if (!string.IsNullOrEmpty(config.url.user))
     {
         var username = config.url.user;
         var password = config.url.password;
         var encoded  =
             Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
         request.Headers.Add("Authorization", "Basic " + encoded);
     }
 }