Exemplo n.º 1
0
        /// <summary></summary>
        protected async Task <CaptchaResponse> TryGetResult
            (CaptchaTask task, CancellationToken cancellationToken = default)
        {
            var             start = DateTime.Now;
            CaptchaResponse result;

            // Initial delay
            await Task.Delay(PollingInterval);

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                result = await CheckResult(task, cancellationToken);

                await Task.Delay(PollingInterval);
            }while (!task.Completed && DateTime.Now - start < Timeout);

            if (!task.Completed)
            {
                throw new TimeoutException();
            }

            return(result);
        }
        /// <inheritdoc/>
        protected async override Task <CaptchaResponse> CheckResult
            (CaptchaTask task, CancellationToken cancellationToken = default)
        {
            string response;

            if (task.Type == CaptchaType.GeeTest)
            {
                response = await httpClient.GetStringAsync
                               ("captchaapi/getrecaptchatext.ashx",
                               GetAuthPair()
                               .Add("action", "GETTEXT")
                               .Add("captchaID", task.Id),
                               cancellationToken)
                           .ConfigureAwait(false);
            }
            else
            {
                response = await httpClient.PostToStringAsync
                               ("captchaapi/GetRecaptchaTextToken.ashx",
                               GetAuthPair()
                               .Add("action", "GETTEXT")
                               .Add("captchaID", task.Id),
                               cancellationToken)
                           .ConfigureAwait(false);
            }

            if (response.Contains("NOT_DECODED"))
            {
                return(default);
Exemplo n.º 3
0
        /// <inheritdoc/>
        protected async override Task <CaptchaResponse> CheckResult(CaptchaTask task, CancellationToken cancellationToken = default)
        {
            var response = await httpClient.GetAsync($"captcha/{task.Id}", cancellationToken);

            var query = HttpUtility.ParseQueryString(await DecodeIsoResponse(response));

            if (query["text"] == string.Empty)
            {
                return(default);
Exemplo n.º 4
0
        private async Task <CaptchaResponse> TryGetResult
            (string response, CaptchaType type, CancellationToken cancellationToken = default)
        {
            if (IsError(response))
            {
                throw new TaskCreationException(response);
            }

            var task = new CaptchaTask(response, type);

            return(await TryGetResult(task, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 5
0
        private async Task <CaptchaResponse> TryGetResult
            (NameValueCollection response, CaptchaType type, CancellationToken cancellationToken = default)
        {
            if (IsError(response))
            {
                throw new TaskCreationException(GetErrorMessage(response));
            }

            var task = new CaptchaTask(response["captcha"], type);

            return(await TryGetResult(task, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 6
0
        internal async Task <CaptchaResponse> TryGetResult
            (Response response, CaptchaType type, CancellationToken cancellationToken = default)
        {
            if (response.IsErrorCode)
            {
                throw new TaskCreationException(response.Request);
            }

            var task = new CaptchaTask(response.Request, type);

            return(await TryGetResult(task, cancellationToken).ConfigureAwait(false));
        }
        private async Task <CaptchaResponse> TryGetResult
            (TaskCreationResponse response, CaptchaType type, CancellationToken cancellationToken = default)
        {
            if (response.IsError)
            {
                throw new TaskCreationException($"{response.ErrorCode}: {response.ErrorDescription}");
            }

            var task = new CaptchaTask(response.TaskId, type);

            return(await TryGetResult(task, cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 8
0
        /// <inheritdoc/>
        protected async override Task <CaptchaResponse> CheckResult
            (CaptchaTask task, CancellationToken cancellationToken = default)
        {
            var response = await httpClient.GetStringAsync
                               ("index.cgi",
                               GetAuthPair()
                               .Add("action", "usercaptchacorrectdata")
                               .Add("id", task.Id),
                               cancellationToken)
                           .ConfigureAwait(false);

            // Not solved yet
            if (string.IsNullOrEmpty(response) || response.Contains("CAPTCHA_NOT_READY"))
            {
                return(default);
Exemplo n.º 9
0
        /// <summary></summary>
        protected async override Task <CaptchaResponse> CheckResult
            (CaptchaTask task, CancellationToken cancellationToken = default)
        {
            var response = await httpClient.GetStringAsync
                               ("res.php",
                               new StringPairCollection()
                               .Add("key", ApiKey)
                               .Add("action", "get")
                               .Add("id", task.Id.ToString())
                               .Add("json", Convert.ToInt32(UseJsonFlag).ToString()),
                               cancellationToken);

            if (response.Contains("CAPCHA_NOT_READY"))
            {
                return(default);
        /// <inheritdoc/>
        protected async override Task <CaptchaResponse> CheckResult
            (CaptchaTask task, CancellationToken cancellationToken = default)
        {
            var response = await httpClient.PostJsonToStringAsync
                               ("getTaskResult",
                               new GetTaskResultRequest()
            {
                ClientKey = ApiKey, TaskId = (int)task.Id
            },
                               cancellationToken).ConfigureAwait(false);

            var result = response.Deserialize <GetTaskResultResponse>();

            if (!result.IsReady)
            {
                return(default);
Exemplo n.º 11
0
 public CreateCaptchaTaskRequest(string apiKey, string base64)
 {
     clientKey = apiKey; task = new CaptchaTask(base64);
 }
Exemplo n.º 12
0
 /// <summary></summary>
 protected virtual Task <CaptchaResponse> CheckResult
     (CaptchaTask task, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }