Exemplo n.º 1
0
        public static MemoryStream DownloadWithBlocking(string url, IEnumerable <string> request_headers, out WebHeaderCollection header_collection)
        {
            using (WebClientWithCompression wc = new WebClientWithCompression())
            {
                DownloadProgressReporter dpr = new DownloadProgressReporter(wc);
                wc.Proxy = Configuration.Proxy;

                if (null != request_headers)
                {
                    foreach (string request_header in request_headers)
                    {
                        wc.Headers.Add(request_header);
                    }
                }

                // same headers as sent by modern Chrome.
                // Gentlemen, start your prayer wheels!
                wc.Headers.Add("Cache-Control", "no-cache");
                wc.Headers.Add("Pragma", "no-cache");
                wc.Headers.Add("User-agent", Configuration.WebUserAgent);

                byte[] data = wc.DownloadData(new Uri(url));
                header_collection = wc.ResponseHeaders;
                return(new MemoryStream(data));
            }
        }
Exemplo n.º 2
0
            private void CleanupAfterDownload()
            {
                if (null != wc)
                {
                    wc.DownloadProgressChanged -= wc_DownloadProgressChanged;
                    wc.DownloadDataCompleted   -= wc_DownloadDataCompleted;

                    wc.Dispose();
                }
                wc = null;
            }
Exemplo n.º 3
0
            public DownloadAsyncTracker(IWebProxy proxy, string url)
            {
                // Init
                this.ProgressPercentage             = 0;
                this.DownloadDataCompletedEventArgs = null;

                // Start the download
                wc       = new WebClientWithCompression();
                wc.Proxy = proxy;
                wc.DownloadProgressChanged += this.wc_DownloadProgressChanged;
                wc.DownloadDataCompleted   += this.wc_DownloadDataCompleted;
                wc.DownloadDataAsync(new Uri(url));
            }
Exemplo n.º 4
0
        public static void DownloadWithBlocking(IWebProxy proxy, string url, IEnumerable <string> request_headers, out MemoryStream ms, out WebHeaderCollection header_collection)
        {
            using (WebClientWithCompression wc = new WebClientWithCompression())
            {
                DownloadProgressReporter dpr = new DownloadProgressReporter(wc);
                wc.Proxy = proxy;

                if (null != request_headers)
                {
                    foreach (string request_header in request_headers)
                    {
                        wc.Headers.Add(request_header);
                    }
                }

                byte[] data = wc.DownloadData(url);
                header_collection = wc.ResponseHeaders;
                ms = new MemoryStream(data);
            }
        }
Exemplo n.º 5
0
            public DownloadAsyncTracker(string url)
            {
                // Init
                ProgressPercentage             = 0;
                DownloadDataCompletedEventArgs = null;

                // Start the download
                wc       = new WebClientWithCompression();
                wc.Proxy = Configuration.Proxy;

                wc.DownloadProgressChanged += wc_DownloadProgressChanged;
                wc.DownloadDataCompleted   += wc_DownloadDataCompleted;

                // same headers as sent by modern Chrome.
                // Gentlemen, start your prayer wheels!
                wc.Headers.Add("Cache-Control", "no-cache");
                wc.Headers.Add("Pragma", "no-cache");
                wc.Headers.Add("User-agent", Configuration.WebUserAgent);

                wc.DownloadDataAsync(new Uri(url));
            }