예제 #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));
            }
        }
예제 #2
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);
            }
        }