Example #1
0
        public static SnapshotData DownloadImage(string url, string username, string password, bool useCredentials)
        {
            SnapshotData   snapshot = new SnapshotData();
            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(url);

            request.KeepAlive = false;

            if (useCredentials)
            {
                request.Credentials = new NetworkCredential(username, password);
            }

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream(60000))
                    {
                        if (response.ContentType.Contains("image") && stream != null)
                        {
                            stream.CopyTo(ms);
                            snapshot.Data        = ms.ToArray();
                            snapshot.ContentType = response.Headers["Content-Type"];
                        }
                    }
                }
            }

            return(snapshot);
        }
Example #2
0
        public static SnapshotData DownloadImage(string url, string username, string password, bool useCredentials)
        {
            SnapshotData snapshot = new SnapshotData();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.KeepAlive = false;

            if (useCredentials)
                request.Credentials = new NetworkCredential(username, password);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream(60000))
                    {
                        if (response.ContentType.Contains("image") && stream != null)
                        {
                            stream.CopyTo(ms);
                            snapshot.Data = ms.ToArray();
                            snapshot.ContentType = response.Headers["Content-Type"];
                        }
                    }
                }
            }

            return snapshot;
        }