从URL获取图片并保存到本地


     ///   <summary> 
        ///  HttpWebRequest Property
        ///   </summary> 
        ///   <param name="fileName">文件名称</param> 
        ///   <param name="url">图片地址</param> 
        ///   <param name="localPath">本地路径("D:\\imgdow")</param>       
        public static void 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();
        }

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号