예제 #1
0
        /// <summary>
        /// Validates a Recaptcha V2 response.
        /// </summary>
        /// <param name="recaptchaResponse">g-recaptcha-response form response variable (HttpContext.Current.Request.Form["g-recaptcha-response"])</param>
        /// <returns>RecaptchaValidationResult</returns>
        /// <remarks>
        /// 8/4/2015 - Matt Olson: Initial creation.
        /// </remarks>
        public RecaptchaValidationResult Validate(string recaptchaResponse)
        {
            var result = new RecaptchaValidationResult();

            var req = (HttpWebRequest)WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=" + SecretKey + "&response="
                                                        + recaptchaResponse + "&remoteip=" + GetClientIp());

            //Google recaptcha Response
            using (WebResponse wResponse = req.GetResponse())
            {
                using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
                {
                    string jsonResponse = readStream.ReadToEnd();

                    var js = new JavaScriptSerializer();
                    result = js.Deserialize <RecaptchaValidationResult>(jsonResponse.Replace("error-codes", "ErrorMessages").Replace("success", "Succeeded"));// Deserialize Json
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Validates a Recaptcha V2 response.
        /// </summary>
        /// <param name="recaptchaResponse">g-recaptcha-response form response variable (HttpContext.Current.Request.Form["g-recaptcha-response"])</param>
        /// <returns>RecaptchaValidationResult</returns>
        /// <remarks>
        /// 8/4/2015 - Matt Olson: Initial creation.
        /// </remarks>
        public RecaptchaValidationResult Validate(string recaptchaResponse)
        {
            var result = new RecaptchaValidationResult();

            var req = (HttpWebRequest)WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=" + SecretKey + "&response="
              + recaptchaResponse + "&remoteip=" + GetClientIp());

            //Google recaptcha Response
            using (WebResponse wResponse = req.GetResponse())
            {
                using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
                {
                    string jsonResponse = readStream.ReadToEnd();

                    var js = new JavaScriptSerializer();
                    result = js.Deserialize<RecaptchaValidationResult>(jsonResponse.Replace("error-codes", "ErrorMessages").Replace("success", "Succeeded"));// Deserialize Json
                }
            }

            return result;
        }