コード例 #1
0
ファイル: SyncDownloader.cs プロジェクト: justMaku/W3DT
        public void DownloadFile(string url, string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
                using (Stream stream = resp.GetResponseStream())
                    using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        CacheMetaData.AddToCache(resp, path);
                        CopyToStream(stream, fs, resp.ContentLength);
                    }
        }
コード例 #2
0
ファイル: SyncDownloader.cs プロジェクト: justMaku/W3DT
        public CacheMetaData GetMetaData(string url, string file)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "HEAD";

                using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
                {
                    return(CacheMetaData.AddToCache(resp, file));
                }
            }
            catch
            {
                return(null);
            }
        }