如何从服务器端检查多个Google验证码?

时间:2018-09-12 10:15:42

标签: c# asp.net webforms recaptcha

我的页面中有两个google-recaptcha v2,一个用于登录,另一个用于注册,我需要从服务器端进行检查

        public static bool IsValidateCaptcha(HttpRequest request)
    {

        string recaptchaSecret = ConfigurationSettings.AppSettings["ReCaptcha_SecretKey"];


        string response = request["g-recaptcha-response"];
        bool valid = false;
        string url = "https://www.google.com/recaptcha/api/siteverify? secret=" + recaptchaSecret + "&response=" + response;
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

        try
        {
            using (WebResponse wResponse = req.GetResponse())
            {
                using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
                {
                    string jsonResponse = readStream.ReadToEnd();
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    Models.CaptchaResponseObject data = js.Deserialize<Models.CaptchaResponseObject>(jsonResponse);// Deserialize Json

                    valid = Convert.ToBoolean(data.success);
                }
            }
            return valid;
        }
        catch (WebException ex)
        {
            Logger.Error(ex);
            return valid;
        }
    }

我写了上面的代码来检查Recaptcha服务器端,问题是我有两个Recaptcha 就像在multiple google recaptcha

中一样

我从服务器端检查它们,但是我需要在一个请求下就其中之一使用服务器端

0 个答案:

没有答案