Пример #1
0
        /// <inheritdoc/>
        public async override Task <StringResponse> SolveImageCaptchaAsync
            (string base64, ImageCaptchaOptions options = null, CancellationToken cancellationToken = default)
        {
            var content = GetAuthPair()
                          .Add("function", "picture2")
                          .Add("pict_type", 0)
                          .Add("lang", options.CaptchaLanguage.ToISO6391Code())
                          .ToMultipartFormDataContent();

            var buffer = Convert.FromBase64String(base64);

            content.Add(new ByteArrayContent(buffer), "pict");

            var response = await httpClient.PostMultipartToStringAsync("",
                                                                       content,
                                                                       cancellationToken)
                           .ConfigureAwait(false);

            if (DeCaptcherResponse.TryParse(response, out DeCaptcherResponse resp))
            {
                return new StringResponse {
                           Id = GetCaptchaId(resp), Response = resp.Text
                }
            }
            ;

            throw new TaskSolutionException(response);
        }
Пример #2
0
        /// <inheritdoc/>
        public async override Task <StringResponse> SolveRecaptchaV2Async
            (string siteKey, string siteUrl, string dataS = "", bool enterprise = false, bool invisible = false,
            Proxy proxy = null, CancellationToken cancellationToken             = default)
        {
            if (proxy != null)
            {
                if (proxy.RequiresAuthentication)
                {
                    throw new NotSupportedException("Authenticated proxies are not supported");
                }

                if (proxy.Type != ProxyType.SOCKS4 && proxy.Type != ProxyType.SOCKS5)
                {
                    throw new NotSupportedException("Only SOCKS proxies are supported");
                }

                if (siteUrl.StartsWith("https"))
                {
                    throw new NotSupportedException("Only http sites are supported");
                }
            }

            var pairs = GetAuthPair()
                        .Add("function", "proxy_url")
                        .Add("url", siteUrl)
                        .Add("key", siteKey);

            if (proxy != null)
            {
                pairs.Add("proxy", $"{proxy.Host}:{proxy.Port}");
            }

            var response = await httpClient.PostMultipartToStringAsync("",
                                                                       pairs.ToMultipartFormDataContent(),
                                                                       cancellationToken)
                           .ConfigureAwait(false);

            if (DeCaptcherResponse.TryParse(response, out DeCaptcherResponse resp))
            {
                return new StringResponse {
                           Id = GetCaptchaId(resp), Response = resp.Text
                }
            }
            ;

            throw new TaskSolutionException(response);
        }
Пример #3
0
        /// <inheritdoc/>
        public async override Task <StringResponse> SolveTextCaptchaAsync
            (string text, TextCaptchaOptions options = null, CancellationToken cancellationToken = default)
        {
            var response = await httpClient.PostMultipartToStringAsync("",
                                                                       GetAuthPair()
                                                                       .Add("function", "picture2")
                                                                       .Add("pict", text)
                                                                       .Add("pict_type", 83)
                                                                       .Add("lang", options.CaptchaLanguage.ToISO6391Code())
                                                                       .ToMultipartFormDataContent(),
                                                                       cancellationToken)
                           .ConfigureAwait(false);

            if (DeCaptcherResponse.TryParse(response, out DeCaptcherResponse resp))
            {
                return new StringResponse {
                           Id = GetCaptchaId(resp), Response = resp.Text
                }
            }
            ;

            throw new TaskSolutionException(response);
        }