從URL獲取圖片並保存到本地
阿新 • • 發佈:2018-01-15
pos ons ring file timeout str oca pan load
/// <summary> /// HttpWebRequest Property /// </summary> /// <param name="fileName">文件名稱</param> /// <param name="url">圖片地址</param> /// <param name="localPath">本地路徑("D:\\imgdow")</param> public staticvoid DownloadOneFileByURL(string fileName, string url, string localPath) { Stream s = null; System.Net.HttpWebRequest request = null; System.Net.HttpWebResponse response = null; request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.Timeout= 5000; // 超時時間 response = (System.Net.HttpWebResponse)request.GetResponse(); s = response.GetResponseStream(); var imgs = Image.FromStream(s); imgs.Save(localPath + $"/{fileName}.jpg"); s.Close(); }
從URL獲取圖片並保存到本地