http下载指定文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Simon1003/article/details/80345609

http下载指定文件 :这里以pdf文件为例

函数代码:

/// <summary>
        /// http下载文件
        /// </summary>
        /// <param name="pdfURL">http文件路径</param>
        /// <param name="destAdrrFileName">保存文件地址+文件名称和后缀</param>
        private void DownLoadPDF(string pdfURL,string destAdrrFileName)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pdfURL);
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream responseStream = response.GetResponseStream();
            Stream stream = new FileStream(@destAdrrFileName, FileMode.Create);
            byte[] bArr = new byte[1024];
            int size = responseStream.Read(bArr, 0, bArr.Length);
            while (size > 0)
            {
                stream.Write(bArr, 0, size);
                size = responseStream.Read(bArr, 0, bArr.Length);
            }
            stream.Close();
            responseStream.Close();
            
        }

阅读更多

扫码向博主提问

拳击手.

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • C#
  • MVC
  • JSON
去开通我的Chat快问
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页