public void DownloadFile(string url, string path) { Directory.CreateDirectory(Path.GetDirectoryName(path)); //using (var client = new HttpClient()) //{ // var msg = client.GetAsync(url).Result; // using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) // { // //CacheMetaData.AddToCache(resp, path); // //CopyToStream(stream, fs, resp.ContentLength); // msg.Content.CopyToAsync(fs).Wait(); // } //} HttpWebRequest request = WebRequest.CreateHttp(url); using (HttpWebResponse resp = (HttpWebResponse)request.GetResponseAsync().Result) using (Stream stream = resp.GetResponseStream()) using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { CacheMetaData.AddToCache(resp, path); CopyToStream(stream, fs, resp.ContentLength); } }
public void DownloadFile(string url, string path) { Directory.CreateDirectory(Path.GetDirectoryName(path)); HttpWebRequest request = WebRequest.CreateHttp(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); } }
public CacheMetaData GetMetaData(string url, string file) { try { HttpWebRequest request = WebRequest.CreateHttp(url); request.Method = "HEAD"; using (HttpWebResponse resp = (HttpWebResponse)request.GetResponseAsync().Result) { return(CacheMetaData.AddToCache(resp, file)); } } catch { return(null); } }