资源简介
C#HttpWebRequest大文件断点续传类,简洁,清晰易懂,大家有空可以下载拿去研究
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace Thunder8
{
public class HttpUploader
{
const long partLength = 1024 * 1024 * 100;
const string succuessFlag = “1“;
public static string Upload(string fileName string httpUrllong seekPosition)
{
string result = string.Empty;
FileStream fs = File.OpenRead(fileName);
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream requestStream = null;
Stream responseStream = null;
try
{
long fileLength = fs.Length;
long endPosition = seekPosition + partLength;
request = (HttpWebRequest)HttpWebRequest.Create(httpUrl);
request.Timeout = -1;
request.ContentType = “application/octet-stream“;
request.AddRange((int)seekPosition);
requestStream = request.GetRequestStream();
byte[] buffer = new byte[1024 * 10];
fs.Seek(seekPosition SeekOrigin.Begin);
int readLength = fs.Read(buffer 0 buffer.Length);
while (seekPosition < endPosition && readLength > 0)
{
requestStream.Write(buffer 0 readLength);
requestStream.Flush();
seekPosition += readLength;
readLength = fs.Read(buffer 0 buffer.Length);
}
response = (HttpWebResponse)request.GetResponse();
- 上一篇:仓库管理系统ASP.NET源码带数据库及其结构图
- 下一篇:C#透明窗体画图电子尺
评论
共有 条评论