/// <summary> /// Submit recaptcha and get it's captcha ID /// Check API docs for more info on how to get page_url and sitekey /// </summary> /// <param name="page_url">page url (check API docs)</param> /// <param name="sitekey">site key (check API docs)</param> /// <param name="proxy">IP:Port (optional)</param> /// <param name="proxy_type">ProxyType (optional)</param> /// <returns></returns> public string submit_recaptcha(string page_url, string sitekey, string proxy = "") { // 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"); } string url = ""; // create dict (params) Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("action", "UPLOADCAPTCHA"); d.Add("pageurl", page_url); d.Add("googlekey", sitekey); // add proxy params if given if (!string.IsNullOrWhiteSpace(proxy)) { d.Add("proxy", proxy); } if (!string.IsNullOrWhiteSpace(this._username)) { d.Add("username", this._username); d.Add("password", this._password); url = RECAPTCHA_SUBMIT_ENDPOINT; } else { d.Add("token", this._access_token); url = RECAPTCHA_SUBMIT_ENDPOINT_TOKEN; } // affiliate id if (!string.IsNullOrWhiteSpace(this._affiliateid) && this._affiliateid.ToString() != "0") { d.Add("affiliateid", this._affiliateid); } var post_data = Utils.list_to_params(d); // transform dict to params string response = Utils.POST(url, 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 }
/// <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"); } string url = ""; // init params object Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("action", "GETTEXT"); d.Add("captchaid", captcha_id); if (!string.IsNullOrWhiteSpace(this._username)) { d.Add("username", this._username); d.Add("password", this._password); url = RECAPTCHA_RETRIEVE_ENDPOINT; } else { d.Add("token", this._access_token); url = RECAPTCHA_RETRIEVE_ENDPOINT_TOKEN; } var post_data = Utils.list_to_params(d); // transform dict to params string response = Utils.POST(url, 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 }