예제 #1
0
            public string GetToken()
            {
                // create request to get a captcha token from the api
                string id = CreateRequest();

                if (string.IsNullOrEmpty(id))
                {
                    return(null);
                }

                // wait 15 seconds before checking it for the first time
                Thread.Sleep(15000);

                // how many times to check again before timing out.
                // will wait 5 seconds between each check.
                int extraChecks = 10;

                for (int i = 0; i < extraChecks; i++)
                {
                    _2CaptchaResponse response = CheckRequest(id);

                    // if it's completed, return the 'Message', which will be the token
                    if (response.GetStatus())
                    {
                        return(response.Message);
                    }

                    // if there was an error OR the request timed out (this was the last check) return null
                    if (response.Message.StartsWith("ERROR") || i == extraChecks - 1)
                    {
                        return(null);
                    }

                    // wait 5 seconds before checking again
                    Thread.Sleep(5000);
                }

                return(null);
            }
예제 #2
0
            // response example: {"status":1,"request":"123"}
            private string CreateRequest()
            {
                List <KeyValuePair <string, string> > data = GetDefaultData();

                data.Add(new KeyValuePair <string, string>("method", "userrecaptcha"));
                data.Add(new KeyValuePair <string, string>("googlekey", SiteKey));
                data.Add(new KeyValuePair <string, string>("pageurl", URL));

                FormUrlEncodedContent content = new FormUrlEncodedContent(data);

                using (HttpResponseMessage responseMessage = Client.PostAsync("in.php", content).Result) {
                    string            raw      = responseMessage.Content.ReadAsStringAsync().Result;
                    _2CaptchaResponse response = _2CaptchaResponse.Create(raw);

                    if (!response.GetStatus())
                    {
                        return(null);
                    }
                    else
                    {
                        return(response.Message);
                    }
                }
            }