社区
C#
帖子详情
请问如何用C#中的webrequest,webresponse实现断点续传
Tonny2002
2002-11-23 05:17:45
我用webrequest,webresponse写了一个下载程序,但我无法实现断点续传
因为webresponse.GetResponseStream()返回的stream的canseek为false
stream的position和length不可用该如何解决
...全文
410
3
打赏
收藏
请问如何用C#中的webrequest,webresponse实现断点续传
我用webrequest,webresponse写了一个下载程序,但我无法实现断点续传 因为webresponse.GetResponseStream()返回的stream的canseek为false stream的position和length不可用该如何解决
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
snewxf
2002-11-26
打赏
举报
回复
fileStream = new FileStream(Path,FileMode.Append,FileAccess.Write);
inStream = null;
try
{
HttpWebRequest myre=(HttpWebRequest)WebRequest.Create(URL);
if(fileStream.Length == myre.ContentLength)
{
MessageBox.Show("你以完成下载该程序了","ok");
return;
}
myre.AddRange(Convert.ToInt32(fileStream.Length));//接上次下载的字节开始下载文件
HttpWebResponse response = (HttpWebResponse)myre.GetResponse();
inStream =response .GetResponseStream();
this.progressBar1.Maximum = total;
this.progressBar1.Minimum =0;
int length = 1024;
byte[] buffer = new byte[1025];
int readerLength = 0,currentLength=0;
while((readerLength =inStream.Read(buffer,0,length))> 0)
{
currentLength += readerLength ;
fileStream.Write(buffer,0,readerLength);
this.progressBar1.Value =currentLength + countByte;
}
fileStream.Close();
inStream.Close();
File.Delete(Application.StartupPath +@"\FileLength.txt");
MessageBox.Show("down 成功","ok");
socket没玩过!好运吧!!!!!!!!
Tonny2002
2002-11-25
打赏
举报
回复
但是我如果用socket如何实现?
yarshray
2002-11-23
打赏
举报
回复
断点续传首先要服务器支持
通常是用socket编写
断点续传和多线程下载 (2002年第3期)
http://www.csdn.net/magazine/download.shtm
Unity
Web
Request
使用集锦
C#
游戏开发基础知识 Unity3D基础知识 Unity3D2D游戏开发基础 Unity3D独立游戏开发入门
C#
实现
断点续传
功能
【代码】
C#
实现
断点续传
功能。
C#
使用
Web
Response
实现
断点续传
(Http
Web
Request
)
Web
Request
.Create(URL); if (fileStream.Length == myre.ContentLength) { MessageBox.Show( " 你以完成下载该程序了 " , " ok " ); return ; } myre...
C#
断点续传
原理与
实现
} } /// /// 下载一个文件块,利用该方法可自行
实现
多线程
断点续传
/// /// URL 地址 /// 保存到本地的路径文件名 /// 块大小 public void DownloadFileChunk(string Address, string FileName, int FromPosition, ...
C#
开源强大的Http
Web
Request
断点续传
库再也不怕下载失败啦
只是网上很多的资料比较杂,经过研究和整合,并且应用到我的项目
中
,大约1万用户的使用。证明我这个下载库是十分稳定的。现在开源出来。 主要就是2个类。拷贝到自己的代码
中
。 第一个辅助类: using System; using ...
C#
110,536
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章