Exemple #1
0
        /// <summary>
        /// Retrieve recaptcha response using captcha ID
        /// </summary>
        /// <param name="captcha_id"></param>
        /// <returns></returns>
        public string retrieve_captcha(string captcha_id)
        {
            // check if ID is OK
            if (string.IsNullOrWhiteSpace(captcha_id))
            {
                throw new Exception("captcha ID is null or empty");
            }

            // init params object
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("action", "GETTEXT");
            d.Add("captchaid", captcha_id);
            d.Add("token", this._access_token);

            var    post_data = Utils.list_to_params(d);                                                             // transform dict to params
            string response  = Utils.POST(RECAPTCHA_RETRIEVE_ENDPOINT_TOKEN, post_data, USER_AGENT, this._timeout); // make request

            if (response.Contains("ERROR:"))
            {
                var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
                // in this case, if we get NOT_DECODED, we don't need it saved to obj
                // because it's used by bool in_progress(int captcha_id) as well
                if (!response_err.Contains("NOT_DECODED"))
                {
                    this._error = response_err;
                }
                throw new Exception(response_err);
            }

            // set as recaptcha response and return
            this._recaptcha = new Recaptcha(captcha_id);
            this._recaptcha.set_response(response);
            return(this._recaptcha.response());        // return captcha text
        }
Exemple #2
0
        public string submit_recaptcha(string page_url, string sitekey)
        {
            // check given vars
            if (string.IsNullOrWhiteSpace(page_url))
            {
                throw new Exception("page_url variable is null or empty");
            }
            if (string.IsNullOrWhiteSpace(sitekey))
            {
                throw new Exception("sitekey variable is null or empty");
            }

            // create dict (params)
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("action", "UPLOADCAPTCHA");
            d.Add("pageurl", page_url);
            d.Add("googlekey", sitekey);
            d.Add("token", this._access_token);
            d.Add("affiliateid", this._affiliateid);

            var    post_data = Utils.list_to_params(d);                                                           // transform dict to params
            string response  = Utils.POST(RECAPTCHA_SUBMIT_ENDPOINT_TOKEN, post_data, USER_AGENT, this._timeout); // make request

            if (response.Contains("ERROR:"))
            {
                var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
                this._error = response_err;
                throw new Exception(response_err);
            }

            // set as recaptcha [id] response and return
            var r = new Recaptcha(response);

            this._recaptcha = r;
            return(this._recaptcha.captcha_id());        // return captcha id
        }