zoukankan      html  css  js  c++  java
  • 通过Src下载图片存到指定目录

               string src = temppartsrc + "." + pictype;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(src);
                request.AllowAutoRedirect = true;

                WebProxy proxy = new WebProxy();
                proxy.BypassProxyOnLocal = true;
                proxy.UseDefaultCredentials = true;
                request.Proxy = proxy;
                WebResponse response = request.GetResponse();
                string virthpath = "";
                using (Stream stream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        Byte[] buffer = new Byte[1024];
                        int current = 0;
                        while ((current = stream.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            ms.Write(buffer, 0, current);
                        }
                        byte[] arry = ms.ToArray();
                         virthpath = "./image/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "." + pictype;
                        string path = Server.MapPath(virthpath);
                        File.WriteAllBytes(path, arry);
                    }
                }

  • 相关阅读:
    搭建 springboot selenium 网页文件转图片环境
    洛谷P1352没有上司的舞会-题解
    错误集合
    洛谷P1434滑雪-题解
    洛谷P1278单词游戏-题解
    洛谷P1219八皇后-题解
    洛谷P1443马的遍历-题解
    洛谷P1135奇怪的电梯-题解
    经验集合
    洛谷P1019单词接龙-题解
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7007000.html
Copyright © 2011-2022 走看看