示例#1
0
        private HttpClient CreateRequest()
        {
            var firstHandle = new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
                Credentials            = CredentialCache.DefaultCredentials,
                AllowAutoRedirect      = false,
                CookieContainer        = new CookieContainer()
            };

            if (Cookies != null)
            {
                firstHandle.CookieContainer.Add(Cookies);
            }

            var cloudFlareHandler = new ClearanceHandler(firstHandle);
            var request           = new HttpClient(cloudFlareHandler);

            if (Referrer != null)
            {
                request.DefaultRequestHeaders.Referrer = new Uri(Referrer);
            }

            // Add the Headers for "User Agent"
            return(request);
        }
示例#2
0
        private async Task <string> _ExecuteHttpRequest(string filmUrl)
        {
            //            var client = !_useProxy
            //            ? new HttpClient()
            //            : new HttpClient(new HttpClientHandler
            //            {
            //                UseProxy = true,
            //                Proxy = new WebProxy(_proxyAddress, false)
            //            });


            // Create the clearance handler.
            var handler = new ClearanceHandler
            {
                MaxRetries = 2 // Optionally specify the number of retries, if clearance fails (default is 3).
            };

            // Create a HttpClient that uses the handler to bypass CloudFlare's JavaScript challange.
            var client = new HttpClient(handler);

            var url = _PrepareUrl(filmUrl);

            var response = await client.GetAsync(url);

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            return(content);
        }
示例#3
0
        public async Task SolveErrorBadConfig()
        {
            var handler = new ClearanceHandler("http://localhost:44445")
            {
                UserAgent  = null,
                MaxTimeout = 60000
            };

            var client = new HttpClient(handler);

            try
            {
                await client.GetAsync(_protectedUri);

                Assert.Fail("Exception not thrown");
            }
            catch (FlareSolverrException e)
            {
                Assert.IsTrue(e.Message.Contains("Error connecting to FlareSolverr server"));
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception: " + e);
            }
        }
示例#4
0
        public async Task SolveErrorProxy()
        {
            var handler = new ClearanceHandler(Settings.FlareSolverrApiUrl)
            {
                MaxTimeout = 60000,
                ProxyUrl   = "http://localhost:44445"
            };

            var client = new HttpClient(handler);

            try
            {
                await client.GetAsync(Settings.ProtectedUri);

                Assert.Fail("Exception not thrown");
            }
            catch (HttpRequestException e)
            {
                Assert.IsTrue(e.Message.Contains("FlareSolverr was unable to process the request, please check FlareSolverr logs. Message: Error: Unable to process browser request. Error: NS_ERROR_PROXY_CONNECTION_REFUSED at " + Settings.ProtectedUri));
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception: " + e);
            }
        }
        public Client()
        {
            var handler = new ClearanceHandler();

            httpClient = new HttpClient(handler);
            context    = BrowsingContext.New();
        }
示例#6
0
        public HttpWebClient2(IProcessService p, Logger l, IConfigurationService c)
            : base(p: p,
                   l: l,
                   c: c)
        {
            cookies = new CookieContainer();
            var      useProxy    = false;
            WebProxy proxyServer = null;

            if (Startup.ProxyConnection != null)
            {
                proxyServer = new WebProxy(Startup.ProxyConnection, false);
                useProxy    = true;
            }

            clearanceHandlr = new ClearanceHandler();
            clientHandlr    = new HttpClientHandler
            {
                CookieContainer        = cookies,
                AllowAutoRedirect      = false, // Do not use this - Bugs ahoy! Lost cookies and more.
                UseCookies             = true,
                Proxy                  = proxyServer,
                UseProxy               = useProxy,
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            clearanceHandlr.InnerHandler = clientHandlr;
            client = new HttpClient(clearanceHandlr);
        }
示例#7
0
        protected void CreateHttpClient()
        {
            cookieContainer = new CookieContainer();

            var handler = new ClearanceHandler(captchaProvider)
            {
                InnerHandler = new HttpClientHandler
                {
                    CookieContainer        = cookieContainer,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                    Proxy = proxy
                },
                MaxTries       = 5,
                ClearanceDelay = 3000
            };

            HttpClient = new HttpClient(handler);

            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.Accept, HttpHeaderValues.GeneralAccept);
            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.AcceptLanguage, HttpHeaderValues.EnUs);
            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.UserAgent, HttpHeaderValues.Chrome75_Win10);
            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.Host, HttpHeaderValues.Host);
            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.UpgradeInsecureRequests, "1");
            HttpClient.DefaultRequestHeaders.Add(HttpHeaders.Connection, HttpHeaderValues.KeepAlive);
        }
示例#8
0
        public static void Sample_AntiCaptcha()
        {
            var target = new Uri("https://uam.hitmehard.fun/HIT");

            var handler = new ClearanceHandler(new AntiCaptchaProvider("YOUR_API_KEY"))
            {
                MaxTries        = 3, // Default value is 3
                MaxCaptchaTries = 2, // Default value is 1
                //ClearanceDelay = 3000  // Default value is the delay time determined in challenge code (not required in captcha)
            };

            var client = new HttpClient(handler);

            client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0");

            try
            {
                var content = client.GetStringAsync(target).Result;
                Console.WriteLine(content);
            }
            catch (AggregateException ex) when(ex.InnerException is CloudflareClearanceException)
            {
                // After all retries, clearance still failed.
                Console.WriteLine(ex.InnerException.Message);
            }
            catch (AggregateException ex) when(ex.InnerException is TaskCanceledException)
            {
                // Looks like we ran into a timeout. Too many clearance attempts?
                // Maybe you should increase client.Timeout as each attempt will take about five seconds.
            }
        }
示例#9
0
        /// <summary>
        /// Returns an web client that have this session cookies.
        /// </summary>
        private HttpClient CreateHttpClient()
        {
            // Handler for bypass Cloudflare
            var handler = new ClearanceHandler()
            {
                InnerHandler = new HttpClientHandler()
                {
                    CookieContainer        = CookieContainer,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                },

                MaxRetries     = 10,
                ClearanceDelay = 3000
            };

            var client = new HttpClient(handler);

            //var client = new HttpClient(new HttpClientHandler() { CookieContainer = CookieContainer });

            client.DefaultRequestHeaders.Add("Accept", "*/*");
            client.DefaultRequestHeaders.Add("Accept-Language", "it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3");
            client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0");
            client.DefaultRequestHeaders.Add("Origin", "https://sketchfab.com");
            client.DefaultRequestHeaders.Add("Connection", "keep-alive");
            client.DefaultRequestHeaders.Add("Cache-Control", "max-age=0");

            return(client);
        }
示例#10
0
        /// <summary>
        /// Returns an web client that have this session cookies.
        /// </summary>
        private HttpClient CreateHttpClient()
        {
            // Handler for bypass Cloudflare
            var handler = new ClearanceHandler()
            {
                InnerHandler = new HttpClientHandler()
                {
                    CookieContainer = CookieContainer
                },
                MaxRetries     = 10,
                ClearanceDelay = 3000
            };

            var client = new HttpClient(handler);

            //var client = new HttpClient(new HttpClientHandler() { CookieContainer = CookieContainer });

            client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            client.DefaultRequestHeaders.Add("Accept-Language", "en-US,en");
            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36");
            client.DefaultRequestHeaders.Add("Host", ConstantsUrL.URL_DOMAIN);
            client.DefaultRequestHeaders.Add("Origin", "https://" + ConstantsUrL.URL_DOMAIN);
            client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
            client.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");
            client.DefaultRequestHeaders.Add("Connection", "keep-alive");

            return(client);
        }
示例#11
0
        private void CloudFlareSessionIdLogin()
        {
            try
            {
                using (var clearanceHandler = new ClearanceHandler {
                    MaxRetries = 2
                })
                    using (var handler = new HttpClientHandler()
                    {
                        CookieContainer = credentialCookies, Proxy = getProxySettings()
                    })
                    {
                        clearanceHandler.InnerHandler = handler;

                        using (var client = new HttpClient(clearanceHandler))
                        {
                            var result = client.GetStringAsync(new Uri(loginURL)).Result;
                        }
                    }
            }
            catch (AggregateException ex) when(ex.InnerException is CloudFlareClearanceException)
            {
                // After all retries, clearance still failed.
                throw new Exception("Cloud flare clearance failed, please wait one minute and try again", ex);
            }
            catch (AggregateException ex) when(ex.InnerException is TaskCanceledException)
            {
                Logger.Log(ex);
                throw;
            }
        }
示例#12
0
        /// <summary>
        /// download HTML as an asynchronous operation.
        /// </summary>
        /// <param name="siteUrl">The URL.</param>
        /// <param name="sitePageType">Type of the page.</param>
        /// <param name="siteSignature">The siteSignature.</param>
        /// <param name="proxy">The proxy.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        public (string html, bool isSuccessful) DownloadHtml(string siteUrl, PageType sitePageType,
            string siteSignature, WebProxy proxy)
        {
            var isUsingProxy = proxy != null;

            var innerHandler = new HttpClientHandler
            {
                AllowAutoRedirect = true,
                MaxAutomaticRedirections = 6,
            };
            if (isUsingProxy)
            {
                innerHandler.Proxy = proxy;
                innerHandler.UseProxy = true;
            }

            var handler = new ClearanceHandler(innerHandler);

            // Create a HttpClient that uses the handler to bypass CloudFlare's JavaScript challange.
            var client = new HttpClient(handler);
            client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", RequesterDefaults.UserAgent);

            // Use the HttpClient as usual. Any JS challenge will be solved automatically for you.
            var html = client.GetStringAsync(siteUrl).Result;

            if (html == null || !html.Contains(siteSignature))
            {
                return (html, false);
            }

            return (html, true);
        }
        public static async Task SamplePostUrlEncoded()
        {
            var handler = new ClearanceHandler("http://localhost:8191/")
            {
                UserAgent  = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
                MaxTimeout = 60000
            };

            var request = new HttpRequestMessage();

            request.Headers.ExpectContinue = false;
            request.RequestUri             = new Uri("https://uam.hitmehard.fun/HIT");
            request.Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
            var postData = new Dictionary <string, string> {
                { "story", "test" }
            };

            request.Content = FormUrlEncodedContentWithEncoding(postData, Encoding.UTF8);
            //request.Content.Headers.Remove("Content-Type");
            //request.Content.Headers.Add("Content-Type", "multipart/form-data; boundary=6");
            request.Method = HttpMethod.Post;

            var client  = new HttpClient(handler);
            var content = await client.SendAsync(request);

            Console.WriteLine(content);
        }
        public List <SniperInfo> FindAll()
        {
            try
            {
                var request = WebRequest.CreateHttp(URL);
                request.Accept  = "application/json";
                request.Method  = "GET";
                request.Timeout = 20000;

                using (var response = request.GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        return(getJsonList(reader.ReadToEnd()));
                    }
                }
            }
            catch (Exception e)
            {
                try {
                    var handler = new ClearanceHandler();

                    // Create a HttpClient that uses the handler.
                    var client = new HttpClient(handler);

                    // Use the HttpClient as usual. Any JS challenge will be solved automatically for you.
                    var content = client.GetStringAsync(URL).Result;
                    return(getJsonList(content));
                } catch (Exception) {
                    Log.Debug("Pokesnipers API error: {0}", e.Message);
                    return(null);
                }
            }
        }
示例#15
0
        public void CreateClient()
        {
            clearanceHandlr = new ClearanceHandler(serverConfig.FlareSolverrUrl)
            {
                MaxTimeout = 55000,
                ProxyUrl   = serverConfig.GetProxyUrl(false)
            };
            clientHandlr = new HttpClientHandler
            {
                CookieContainer        = cookies,
                AllowAutoRedirect      = false, // Do not use this - Bugs ahoy! Lost cookies and more.
                UseCookies             = true,
                Proxy                  = webProxy,
                UseProxy               = (webProxy != null),
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            // custom certificate validation handler (netcore version)
            if (serverConfig.RuntimeSettings.IgnoreSslErrors == true)
            {
                clientHandlr.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
            }
            else
            {
                clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate;
            }

            clearanceHandlr.InnerHandler = clientHandlr;
            client = new HttpClient(clearanceHandlr);
        }
        private static void TimerCallback(Object o)
        {
            var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            var stringChars = new char[16];
            var random      = new Random();

            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }
            var finalString = new String(stringChars);

            if (oldCode == finalString)
            {
            }

            else
            {
                string noExist      = "{*code*: 10038, *message*: *Unknown Gift Code*}";
                string noExistFinal = noExist.Replace('*', '"');
                var    handler      = new ClearanceHandler();

                handler.MaxRetries = 3;

                var client = new HttpClient(handler);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");

                try
                {
                    var content = client.GetStringAsync(new Uri("https://discordapp.com/api/v6/entitlements/gift-codes/" + finalString + "?with_application=false&with_subscription_plan=true")).Result;
                    Console.WriteLine(finalString + " / FOUNDED !" + Environment.NewLine);



                    var s = File.Create("good.txt");
                    s.Dispose();

                    File.WriteAllText("good.txt", finalString);
                }


                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(finalString);
                    Console.ForegroundColor = ConsoleColor.White;
                    if (ex.InnerException.Message.Contains("404"))
                    {
                        Console.WriteLine(" : Invalid Nitro code" + Environment.NewLine);
                    }
                    if (ex.InnerException.Message.Contains("429"))
                    {
                        Console.WriteLine(" : Too many requests / 429" + Environment.NewLine);
                    }
                }
            }
            GC.Collect();
        }
示例#17
0
        public async Task SolveError()
        {
            var uri     = new Uri("https://www.google.bad1/");
            var handler = new ClearanceHandler(Settings.FlareSolverrApiUrl)
            {
                UserAgent  = null,
                MaxTimeout = 60000
            };

            var client = new HttpClient(handler);

            try
            {
                await client.GetAsync(uri);

                Assert.Fail("Exception not thrown");
            }
            catch (HttpRequestException e)
            {
                Assert.IsTrue(e.Message.Contains("Name or service not know"));
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception: " + e);
            }
        }
示例#18
0
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (isFirstLogin)
                {
                    var target  = new Uri(url);
                    var handler = new ClearanceHandler();
                    handler.MaxRetries = 20;
                    var client  = new HttpClient(handler);
                    var rawHtml = client.GetStringAsync(target).Result;
                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(rawHtml);
                    var table = document.DocumentNode.SelectNodes("//table[@class='proxy__t']//tbody/tr");
                    foreach (HtmlNode item in table)
                    {
                        HtmlNode ipTd = item.ChildNodes.FirstOrDefault(x => x.HasClass("tdl"));
                        string   port = ipTd.NextSibling.InnerText;

                        if (ipTd != null)
                        {
                            ipList.Add(ipTd.InnerText + ":" + port);
                        }
                    }
                    isFirstLogin = false;
                }
                ChangeProxy();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#19
0
文件: Etc.cs 项目: Benjababe/HLTV-CLI
        public static HtmlDocument GetDocFromURL(string url, bool retry = false)
        {
            if (retry)
            {
                Console.WriteLine("Retrying now...");
            }
            if (url == "")
            {
                return(new HtmlDocument());
            }
            Uri target = new Uri(url);
            ClearanceHandler cHandler = new ClearanceHandler {
                MaxTries       = 3,
                ClearanceDelay = 3000
            };

            HttpClientHandler handler    = new HttpClientHandler();
            HttpClient        httpClient = new HttpClient(cHandler);

            string source = "";

            try {
                source = httpClient.GetStringAsync(target).Result;
            } catch (AggregateException ex) {
                Console.WriteLine("Exception " + ex.Message + " Error with getting " + target + ". Retrying in 2 seconds...");
                System.Threading.Thread.Sleep(2000);
                GetDocFromURL(url, retry: true);
            }

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(source);
            return(doc);
        }
示例#20
0
        public async Task SolveErrorNoConfig()
        {
            var handler = new ClearanceHandler("")
            {
                UserAgent  = null,
                MaxTimeout = 60000
            };

            var client = new HttpClient(handler);

            try
            {
                await client.GetAsync(_protectedUri);

                Assert.Fail("Exception not thrown");
            }
            catch (FlareSolverrException e)
            {
                Assert.IsTrue(e.Message.Contains("Challenge detected but FlareSolverr is not configured"));
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception: " + e);
            }
        }
示例#21
0
        public void GetMostInnerHandlerOnDelegatingHandlerReturnsInnerHandler()
        {
            var innerHandler = new HttpClientHandler();
            var handler      = new ClearanceHandler(innerHandler);

            var mostInnerHandler = handler.GetMostInnerHandler();

            Assert.AreSame(innerHandler, mostInnerHandler);
        }
示例#22
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            second++;
            if (second == 3)
            {
                second = 0;
                var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                var stringChars = new char[16];
                var random      = new Random();

                for (int i = 0; i < stringChars.Length; i++)
                {
                    stringChars[i] = chars[random.Next(chars.Length)];
                }
                var finalString = new String(stringChars);
                if (oldCode == finalString)
                {
                }
                else
                {
                    string noExist      = "{*code*: 10038, *message*: *Unknown Gift Code*}";
                    string noExistFinal = noExist.Replace('*', '"');
                    var    handler      = new ClearanceHandler();

                    handler.MaxRetries = 3;

                    var client = new HttpClient(handler);
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                    client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36");

                    try
                    {
                        var content = client.GetStringAsync(new Uri("https://discordapp.com/api/v6/entitlements/gift-codes/" + finalString + "?with_application=false&with_subscription_plan=true")).Result;
                        richTextBox1.Text += finalString + " / EST UN BON CODE !" + Environment.NewLine;
                        File.WriteAllText("good.txt", finalString);
                    }


                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        richTextBox1.Text      += finalString;
                        Console.ForegroundColor = ConsoleColor.White;
                        if (ex.InnerException.Message.Contains("404"))
                        {
                            richTextBox1.Text += " : Code nitro invalide" + Environment.NewLine;
                        }
                        if (ex.InnerException.Message.Contains("429"))
                        {
                            richTextBox1.Text += " : Trop de Requêtes / 429" + Environment.NewLine;
                        }
                    }
                }
            }
        }
示例#23
0
        private void ConnectOverCloudFare()
        {
            var handler = new ClearanceHandler();

            handler.MaxRetries = 5;
            //handler.MaxRetries = ClearanceHandler.DefaultMaxRetries;

            _client         = new HttpClient(handler);
            _client.Timeout = TimeSpan.FromMinutes(5);
        }
示例#24
0
        public PageLoader()
        {
            _clearanceHandler = new ClearanceHandler
            {
                MaxTries       = 5,
                ClearanceDelay = 3000
            };

            _httpClient = new HttpClient(_clearanceHandler, true);
        }
示例#25
0
        public Web()
        {
            var handler = new ClearanceHandler();

            _client         = new HttpClient(handler);
            _insecureClient = new HttpClient(new WebClientRetryHandler
            {
                ServerCertificateCustomValidationCallback = CertificateValidationCallback
            });
        }
        public async Task <List <Episode> > DownloadFeedList()
        {
            try
            {
                List <Episode> episodes = new List <Episode>();

                // Cloudflare solver
                var handler = new ClearanceHandler
                {
                    MaxTries       = 3,
                    ClearanceDelay = 3000
                };

                var client = new HttpClient(handler);
                client.Timeout = TimeSpan.FromSeconds(5);

                var content = await client.GetStringAsync(FeedUrl);

                // Create reader and get items
                XmlTextReader          reader          = new XmlTextReader(new StringReader(content));
                SyndicationFeed        syndicationFeed = SyndicationFeed.Load(reader);
                List <SyndicationItem> feedList        = new List <SyndicationItem>(syndicationFeed.Items);

                foreach (SyndicationItem syndicationItem in feedList)
                {
                    Episode episode = new Episode()
                    {
                        // Name = FileNameParser.GetNameFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString())),
                        Name      = FileNameParser.GetNameFromItem(syndicationItem.Title.Text),
                        Link      = syndicationItem.Links[0].Uri.ToString(),
                        LocalPath = Path.Combine(Logic.LocalConfig.DownloadFolder, syndicationItem.Title.Text)
                    };

                    // double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString()));
                    double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(syndicationItem.Title.Text);
                    if (episodeNumber.Equals(-1))
                    {
                        Log.Warning("Can't parse Feed Episode-number from: " + syndicationItem.Links[0].Uri);
                    }
                    else
                    {
                        episode.EpisodeNumber = episodeNumber;
                    }

                    episodes.Add(episode);
                }

                return(episodes);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "DownloadFeedList Error!");
                return(null);
            }
        }
示例#27
0
        public override List <Movie> retreiveTopMovies()
        {
            //html/body/section[3]/div/div[2]/div[1]/div[2]/div/div[1]
            string title = retrieveLinkMovies();

            try
            {
                var target  = new Uri(title);
                var handler = new ClearanceHandler("http://*****:*****@class,'slides')]");
                if (node == null)
                {
                    return(null);
                }
                var          nodes = node.ChildNodes;
                List <Movie> tmp   = new List <Movie>();
                foreach (HtmlAgilityPack.HtmlNode nod in nodes)
                {
                    if (nod.Name.Contains("#text"))
                    {
                        continue;
                    }
                    string imageLink = nod.Descendants("img").FirstOrDefault().Attributes["src"].Value;
                    Uri    movieLink = new Uri(nod.Descendants("a").FirstOrDefault().Attributes[0].Value);

                    var    toUtf      = nod.Descendants("img").FirstOrDefault().Attributes["alt"].Value;
                    string movieTitle = WebUtility.HtmlDecode(WebUtility.HtmlDecode(toUtf).Replace("streaming", ""));

                    tmp.Add(new Movie(movieTitle, "", 2, imageLink, movieLink));
                }
                for (int i = 0; i < tmp.Count; i++)
                {
                    if (!retrieveStreamLinks(tmp[i]))
                    {
                        tmp.Remove(tmp[i]);
                    }
                }

                return(tmp);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                return(null);
            }
        }
示例#28
0
        public WebParser()
        {
            var handler = new ClearanceHandler {
                MaxRetries = 2 // Optionally specify the number of retries, if clearance fails (default is 3).
            };

            _client = new HttpClient(handler)
            {
                Timeout = TimeSpan.FromSeconds(15)
            };
        }
示例#29
0
        public async Task Connect()
        {
            //Console.Write("Connecting Websocket...");
            const string userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.52";

            var bittrexUri     = new Uri("https://bittrex.com");
            var bittrexFeedUri = new Uri("https://socket.bittrex.com");

            //

            var feedHeaders       = new Dictionary <string, string>();
            var cookieContainer   = new CookieContainer();
            var httpClientHandler = new HttpClientHandler()
            {
                UseCookies      = true,
                CookieContainer = cookieContainer
            };

            var clearanceHandler = new ClearanceHandler(httpClientHandler);
            var httpClient       = new HttpClient(clearanceHandler);

            httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);

            //

            var connConfig = new ConnectionConfiguration()
            {
                CookieContainer = cookieContainer,
                Headers         = feedHeaders
            };

            feedHeaders.Add("User-Agent", userAgent);

            var config = new BittrexFeedConnectionConfiguration()
            {
                // NOTE: Not applicable: AccessToken = "",
                Connection = connConfig
            };

            WSSharpTransport = new BtrexWSwithCFUtil(bittrexFeedUri);

            //

            var request = new HttpRequestMessage(HttpMethod.Get, bittrexUri);
            var content = httpClient.SendAsync(request, CancellationToken.None).Result;

            //

            WSSharpTransport.Connection.CookieContainer = cookieContainer;

            await WSSharpTransport.Connect(config);

            //Console.WriteLine("\rWebsocket Connected.      ");
        }
示例#30
0
        public static async Task SampleGet()
        {
            var handler = new ClearanceHandler(FlareSolverrUrl)
            {
                MaxTimeout = 60000
            };

            var client  = new HttpClient(handler);
            var content = await client.GetStringAsync(ProtectedUrl);

            Console.WriteLine(content);
        }
        public List<SniperInfo> FindAll()
        {
            try
            {
                var handler = new ClearanceHandler();

                // Create a HttpClient that uses the handler.
                using (var client = new HttpClient(handler))
                {

                    // Use the HttpClient as usual. Any JS challenge will be solved automatically for you.
                    var content = client.GetStringAsync(URL).Result;
                    return GetJsonList(content);
                }
            }
            catch (Exception e)
            {
                Log.Debug("Pokesnipers API error: {0}", e.Message);
                return null;
            }
        }
示例#32
0
        private static List<SniperInfo> GetSniperInfoFrom_pokewatchers(ISession session, List<PokemonId> pokemonIds)
        {

            var uri = $"http://pokewatchers.com/api.php?act=grab";

            ScanResult_pokewatchers scanResult_pokewatchers;
            try
            {
                var handler = new ClearanceHandler();

                // Create a HttpClient that uses the handler.
                var client = new HttpClient(handler);

                // Use the HttpClient as usual. Any JS challenge will be solved automatically for you.
                var fullresp = "{ \"pokemons\":" + client.GetStringAsync(uri).Result.Replace(" M", "Male").Replace(" F", "Female").Replace("Farfetch'd", "Farfetchd").Replace("Mr.Maleime", "MrMime") +"}";

                scanResult_pokewatchers = JsonConvert.DeserializeObject<ScanResult_pokewatchers>(fullresp);
            }
            catch (Exception ex)
            {
                // most likely System.IO.IOException
                session.EventDispatcher.Send(new ErrorEvent { Message = "(PokeWatchers.com) " + ex.Message });
                return null;
            }
            if (scanResult_pokewatchers.pokemons != null)
            {
                foreach (var pokemon in scanResult_pokewatchers.pokemons)
                {
                    try
                    {
                        var SnipInfo = new SniperInfo();
                        SnipInfo.Id = pokemon.pokemon;
                        string[] coordsArray = pokemon.cords.Split(',');
                        SnipInfo.Latitude = Convert.ToDouble(coordsArray[0], CultureInfo.InvariantCulture);
                        SnipInfo.Longitude = Convert.ToDouble(coordsArray[1], CultureInfo.InvariantCulture);
                        SnipInfo.TimeStampAdded = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(pokemon.timeadded);
                        SnipInfo.ExpirationTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(pokemon.timeend);
                        SnipeLocations.Add(SnipInfo);
                    }
                    catch
                    {
                    }
                }
                var locationsToSnipe = SnipeLocations?.Where(q =>
                    (!session.LogicSettings.UseTransferIvForSnipe ||
                    (q.IV == 0 && !session.LogicSettings.SnipeIgnoreUnknownIv) ||
                    (q.IV >= session.Inventory.GetPokemonTransferFilter(q.Id).KeepMinIvPercentage)) &&
                    !LocsVisited.Contains(new PokemonLocation(q.Latitude, q.Longitude))
                    && !(q.ExpirationTimestamp != default(DateTime) &&
                    q.ExpirationTimestamp > new DateTime(2016) &&
                    // make absolutely sure that the server sent a correct datetime
                    q.ExpirationTimestamp < DateTime.Now) &&
                    (q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
                    new List<SniperInfo>();

                return locationsToSnipe.OrderBy(q => q.ExpirationTimestamp).ToList();
            }
            else
                return null;
        }
示例#33
0
        private static List<SniperInfo> GetSniperInfoFrom_pokewatchers(ISession session, List<PokemonId> pokemonIds)
        {

            var uri = $"http://pokewatchers.com/api.php?act=grab";

            ScanResult_pokewatchers scanResult_pokewatchers;
            try
            {
                var handler = new ClearanceHandler();

                // Create a HttpClient that uses the handler.
                var client = new HttpClient(handler);
                
                // Our new firewall requires a user agent, or you'll be blocked.
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/511.2 (KHTML, like Gecko) Chrome/15.0.041.151 Safari/555.2");

                string response = null;
                int retries = 0;
                bool retry;

                // Retry up to 5 times, sleeping for 1s between retries.
                do
                {
                    // Use the HttpClient as usual. Any JS challenge will be solved automatically for you.
                    response = client.GetStringAsync(uri).Result;
                    if (response == "You can only request the API every 5 seconds.")
                    {
                        retry = true;
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        retry = false;
                    }
                } while (retry && (retries++ < 5));
                
                if (response == null || response == "You can only request the API every 5 seconds.")
                {
                    response = "[]";
                }
                
                var fullresp = "{ \"pokemons\":" + response + "}".Replace("Mr_mime", "MrMime"); ;
                scanResult_pokewatchers = JsonConvert.DeserializeObject<ScanResult_pokewatchers>(fullresp);
            }
            catch (Exception ex)
            {
                // most likely System.IO.IOException
                session.EventDispatcher.Send(new ErrorEvent { Message = "(PokeWatchers.com) " + ex.Message });
                return null;
            }
            if (scanResult_pokewatchers.pokemons != null)
            {
                foreach (var pokemon in scanResult_pokewatchers.pokemons)
                {
                    try
                    {
                        var SnipInfo = new SniperInfo();
                        SnipInfo.Id = pokemon.pokemon;
                        string[] coordsArray = pokemon.cords.Split(',');
                        SnipInfo.Latitude = Convert.ToDouble(coordsArray[0], CultureInfo.InvariantCulture);
                        SnipInfo.Longitude = Convert.ToDouble(coordsArray[1], CultureInfo.InvariantCulture);
                        SnipInfo.TimeStampAdded = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(pokemon.timeadded);
                        SnipInfo.ExpirationTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(pokemon.timeend);
                        SnipeLocations.Add(SnipInfo);
                    }
                    catch
                    {
                    }
                }
                var locationsToSnipe = SnipeLocations?.Where(q =>
                    (!session.LogicSettings.UseTransferIvForSnipe ||
                    (q.IV == 0 && !session.LogicSettings.SnipeIgnoreUnknownIv) ||
                    (q.IV >= session.Inventory.GetPokemonTransferFilter(q.Id).KeepMinIvPercentage)) &&
                    !LocsVisited.Contains(new PokemonLocation(q.Latitude, q.Longitude))
                    && !(q.ExpirationTimestamp != default(DateTime) &&
                    q.ExpirationTimestamp > new DateTime(2016) &&
                    // make absolutely sure that the server sent a correct datetime
                    q.ExpirationTimestamp < DateTime.Now) &&
                    (q.Id == PokemonId.Missingno || pokemonIds.Contains(q.Id))).ToList() ??
                    new List<SniperInfo>();

                return locationsToSnipe.OrderBy(q => q.ExpirationTimestamp).ToList();
            }
            else
                return null;
        }
示例#34
0
        override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
        {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

            var cookies = new CookieContainer();
            if (!string.IsNullOrEmpty(webRequest.Cookies))
            {
                var uri = new Uri(webRequest.Url);
                foreach (var c in webRequest.Cookies.Split(';'))
                {
                    try
                    {
                        cookies.SetCookies(uri, c);
                    }
                    catch (CookieException ex)
                    {
                        logger.Info("(Non-critical) Problem loading cookie {0}, {1}, {2}", uri, c, ex.Message);
                    }
                }
            }
            var useProxy = false;
            WebProxy proxyServer = null;
            if (Startup.ProxyConnection != null)
            {
                proxyServer = new WebProxy(Startup.ProxyConnection, false);
                useProxy = true;
            }

            ClearanceHandler clearanceHandlr = new ClearanceHandler();
            HttpClientHandler clientHandlr = new HttpClientHandler
            {
                CookieContainer = cookies,
                AllowAutoRedirect = false, // Do not use this - Bugs ahoy! Lost cookies and more.
                UseCookies = true,
                Proxy = proxyServer,
                UseProxy = useProxy
            };

            clearanceHandlr.InnerHandler = clientHandlr;
            var client = new HttpClient(clearanceHandlr);

            if (webRequest.EmulateBrowser)
                client.DefaultRequestHeaders.Add("User-Agent",  BrowserUtil.ChromeUserAgent);
            else
                client.DefaultRequestHeaders.Add("User-Agent", "Jackett/" + configService.GetVersion());
            
            HttpResponseMessage response = null;
            var request = new HttpRequestMessage();
            request.Headers.ExpectContinue = false;
            request.RequestUri = new Uri(webRequest.Url);

            if (webRequest.Headers != null)
            {
                foreach (var header in webRequest.Headers)
                {
                    if (header.Key != "Content-Type")
                    {
                        request.Headers.Add(header.Key, header.Value);
                    }
                }
            }

            if (!string.IsNullOrEmpty(webRequest.RawBody))
            {
                var type = webRequest.Headers.Where(h => h.Key == "Content-Type").Cast<KeyValuePair<string,string>?>().FirstOrDefault();
                if (type.HasValue)
                {
                    var str = new StringContent(webRequest.RawBody);
                    str.Headers.Remove("Content-Type");
                    str.Headers.Add("Content-Type", type.Value.Value);
                    request.Content = str;
                }
                else
                    request.Content = new StringContent(webRequest.RawBody);
                request.Method = HttpMethod.Post;
            }
            else if (webRequest.Type == RequestType.POST)
            {
                request.Content = new FormUrlEncodedContent(webRequest.PostData);
                request.Method = HttpMethod.Post;
            }
            else
            {
                request.Method = HttpMethod.Get;
            }

            response = await client.SendAsync(request);

            var result = new WebClientByteResult();
            result.Content = await response.Content.ReadAsByteArrayAsync();

            foreach (var header in response.Headers)
            {
                IEnumerable<string> value = header.Value;
                result.Headers[header.Key.ToLowerInvariant()] = value.ToArray();
            }

            // some cloudflare clients are using a refresh header
            // Pull it out manually 
            if (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable && response.Headers.Contains("Refresh"))
            {
                var refreshHeaders = response.Headers.GetValues("Refresh");
                var redirval = "";
                var redirtime = 0;
                if (refreshHeaders != null)
                {
                    foreach (var value in refreshHeaders)
                    {
                        var start = value.IndexOf("=");
                        var end = value.IndexOf(";");
                        var len = value.Length;
                        if (start > -1)
                        {
                            redirval = value.Substring(start + 1);
                            result.RedirectingTo = redirval;
                            // normally we don't want a serviceunavailable (503) to be a redirect, but that's the nature
                            // of this cloudflare approach..don't want to alter BaseWebResult.IsRedirect because normally
                            // it shoudln't include service unavailable..only if we have this redirect header.
                            response.StatusCode = System.Net.HttpStatusCode.Redirect;
                            redirtime = Int32.Parse(value.Substring(0, end));
                            System.Threading.Thread.Sleep(redirtime * 1000);
                        }
                    }
                }
            }
            if (response.Headers.Location != null)
            {
                result.RedirectingTo = response.Headers.Location.ToString();
            }
            result.Status = response.StatusCode;

            // Compatiblity issue between the cookie format and httpclient
            // Pull it out manually ignoring the expiry date then set it manually
            // http://stackoverflow.com/questions/14681144/httpclient-not-storing-cookies-in-cookiecontainer
            IEnumerable<string> cookieHeaders;
            var responseCookies = new List<Tuple<string, string>>();

            if (response.Headers.TryGetValues("set-cookie", out cookieHeaders))
            {
                foreach (var value in cookieHeaders)
                {
                    var nameSplit = value.IndexOf('=');
                    if (nameSplit > -1)
                    {
                        responseCookies.Add(new Tuple<string, string>(value.Substring(0, nameSplit), value.Substring(0, value.IndexOf(';') == -1 ? value.Length : (value.IndexOf(';') + 1))));
                    }
                }

                var cookieBuilder = new StringBuilder();
                foreach (var cookieGroup in responseCookies.GroupBy(c => c.Item1))
                {
                    cookieBuilder.AppendFormat("{0} ", cookieGroup.Last().Item2);
                }
                result.Cookies = cookieBuilder.ToString().Trim();
            }
            ServerUtil.ResureRedirectIsFullyQualified(webRequest, result);
            return result;
        }