zoukankan      html  css  js  c++  java
  • http分段下载

    class Downloader
        {
            /// <summary>
            /// 下载一个文件块,利用该方法可自行实现多线程断点续传
            /// </summary>
            /// <param name="Address">URL 地址</param>
            /// <param name="FileName">保存到本地的路径文件名</param>
            /// <param name="Length">块大小</param>
            public void DownloadFileChunk(string Address, string FileName, int FromPosition, int Length)
            {
                HttpWebResponse hwrp = null;
                string a = null;
                try
                {
                    //this._FileName = FileName;
                    HttpWebRequest hwrq = (HttpWebRequest)WebRequest.Create(Address);
                    //hwrq.Credentials = this.m_credentials;
                    hwrq.AddRange(FromPosition);
                    hwrp = (HttpWebResponse)hwrq.GetResponse();
                    a = hwrp.Headers["Content-Disposition"]; //attachment
                    if (a != null)
                    {
                        a = a.Substring(a.LastIndexOf("filename=") + 9);
                    }
                    else
                    {
                        a = FileName;
                    }


                    byte[] buffer = this.ResponseAsBytes(Address, hwrp, Length, FileName);

                }
                catch (Exception e)
                {
                    //add you code.
                }
            }


            internal byte[] ResponseAsBytes(string RequestURL, WebResponse Response, long Length, string FileName)
            {

                byte[] buffers = new byte[Length];
                string s = Response.Headers["Content-Range"];
                //add your code.
                Stream S = Response.GetResponseStream();
                //add your code.
                S.Close();
                Response.Close();

                return buffers;

            }


        }

  • 相关阅读:
    (周日赛) Average is not Fast Enough!
    过山车
    (寒假CF3)B
    (寒假CF3)坑坑坑
    (周六赛1)Sum it up
    畅通工程
    vue 动态添加form表单item 校验问题
    html2canvas转pdf分页隔断问题处理
    vue中html转pdf并下载功能
    一个简单的滑动溢出效果
  • 原文地址:https://www.cnblogs.com/bayonetxxx/p/1989170.html
Copyright © 2011-2022 走看看