コード例 #1
0
ファイル: SMSController.cs プロジェクト: DanBrown95/DownRadar
        public JsonResult Subscribe(string phone, string url, int hours)
        {
            var formattedUrl = UrlProtocolValidator.FormatUrl(url);
            var message      = "You have been subscribed to " + formattedUrl + ". \n\n-DownRadar";
            var sms          = new SMS(phone, message);
            var result       = Send(sms);

            return(Json(new { url = formattedUrl, result }));
        }
コード例 #2
0
        public JsonResult PingUrl(string url)
        {
            var            result     = "";
            HttpStatusCode statusCode = default(HttpStatusCode);

            var formattedUrl = UrlProtocolValidator.FormatUrl(url);

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(formattedUrl);
                request.Method = "HEAD";

                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    if (response != null)
                    {
                        statusCode = response.StatusCode;
                        response.Close();
                    }
                }
                result = "Status: " + statusCode;
            }
            catch (WebException ex)
            {
                if (ex.Status.ToString() == "NameResolutionFailure")
                {
                    result = "Status: Down";
                }
            }
            catch (Exception ex)
            {
                result = "Error: please check the url and try again";
            }

            return(Json(new { url = formattedUrl, result }));
        }