private static async Task <GetTaskResponse> GetCaptchaTask(AntiCaptchaKey antiCaptchaKey,
                                                                   CreateTaskResponse task)
        {
            try
            {
                GetTaskRequest request     = new GetTaskRequest(antiCaptchaKey.ClientKey, task.TaskId);
                string         requestJson = JsonConvert.SerializeObject(request);

                using (HttpRequestMessage httpRequest =
                           new HttpRequestMessage(HttpMethod.Post, AntiCaptchaEndpoints.GetTaskUrl))
                {
                    httpRequest.Content = new StringContent(requestJson, Encoding.UTF8, "application/json");

                    using (HttpResponseMessage httpResponse = await AntiCaptchaGlobals.HttpClient.SendAsync(httpRequest)
                           )
                    {
                        httpResponse.EnsureSuccessStatusCode();
                        string value = await httpResponse.Content.ReadAsStringAsync();

                        GetTaskResponse ret = JsonConvert.DeserializeObject <GetTaskResponse>(value);
                        return(ret);
                    }
                }
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 public static bool RemoveKey(AntiCaptchaKey antiCaptchaKey)
 {
     lock (CaptchaKeys)
     {
         return(CaptchaKeys.Remove(antiCaptchaKey));
     }
 }
Exemplo n.º 3
0
 public static bool AddKey(AntiCaptchaKey antiCaptchaKey)
 {
     lock (CaptchaKeys)
     {
         return(CaptchaKeys.Add(antiCaptchaKey));
     }
 }
Exemplo n.º 4
0
        public static async Task <GetTaskResponse> GetSolvedCaptcha(ICreateTask task)
        {
            GetTaskResponse ret;

            if (!Queue.TryDequeue(out ret))
            {
                AntiCaptchaKey key = GetValidAntiCaptchaKey();
                ret = await key.GetSolvedCaptcha(task);
            }

            if (ret.UsedCount > AntiCaptchaGlobals.CaptchaRetryLimit)
            {
                AntiCaptchaKey key = GetValidAntiCaptchaKey();
                ret = await key.GetSolvedCaptcha(task);
            }

            ret.IncreaseUsedCount();
            return(ret);
        }
Exemplo n.º 5
0
        public static AntiCaptchaKey GetValidAntiCaptchaKey()
        {
            List <AntiCaptchaKey> availableAntiCaptchaKey;

            lock (CaptchaKeys)
            {
                availableAntiCaptchaKey = CaptchaKeys.Where(key => key.IsReady).ToList();
            }

            if (availableAntiCaptchaKey.Count == 0)
            {
                throw new AntiCaptchaException("No valid Anti-Captca keys configured.");
            }

            AntiCaptchaKey ret = availableAntiCaptchaKey[GetRandomNumber(0, availableAntiCaptchaKey.Count)];

            if (ret == null)
            {
                throw new AntiCaptchaException("No valid Anti-Captca keys configured.");
            }


            return(ret);
        }
 protected bool Equals(AntiCaptchaKey other)
 {
     return(string.Equals(ClientKey, other.ClientKey));
 }