zoukankan      html  css  js  c++  java
  • C#图片下载

            #region
            private byte[] GetImageContent(string picName)
            {
                string fileURL = "http://localhost:/img/" + picName;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileURL);
                request.AllowAutoRedirect = true;
                WebProxy proxy = new WebProxy();
                proxy.BypassProxyOnLocal = true;
                proxy.UseDefaultCredentials = true;
                request.Proxy = proxy;
                WebResponse response = request.GetResponse();
                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);
                        }
                        return ms.ToArray();
                    }
                }
            }
            private void WriteResponse(string picName, byte[] content)
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(picName, Encoding.Default));
                Response.AppendHeader("Content-Length", content.Length.ToString());
                Response.BinaryWrite(content);
                Response.Flush();
                Response.End();
            }
            #endregion
    
            protected void btt_Click(object sender, EventArgs e)
            {
                byte[] content = this.GetImageContent("Desert.jpg");
                this.WriteResponse("Desert.jpg", content);
            }
  • 相关阅读:
    c++局部变量在外可用的方法
    Git更新代码到本地
    Redis客户端断开重连功能要点
    android make
    cb-A10 调整分区
    linux内核学习:中断中推后执行的部分
    linux内核学习:中断
    linux内核学习:进程调度
    linux内核学习:进程管理
    ubuntu 安装android源码编译环境 遇到的问题
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2859586.html
Copyright © 2011-2022 走看看