本文整理匯總了C#中System.Web.HttpWorkerRequest.GetPreloadedEntityBodyLength方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpWorkerRequest.GetPreloadedEntityBodyLength方法的具體用法?C# HttpWorkerRequest.GetPreloadedEntityBodyLength怎麽用?C# HttpWorkerRequest.GetPreloadedEntityBodyLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.HttpWorkerRequest
的用法示例。
在下文中一共展示了HttpWorkerRequest.GetPreloadedEntityBodyLength方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AsyncUpload
public AsyncUpload(HttpWorkerRequest wRquest)
{
if (wRquest == null) throw new ArgumentNullException("wRquest");
this.uploadProcess = new UploadProcess(delegate(float f) { });
workerRequest = wRquest;
//當前讀到的流長度
this.preLen = workerRequest.GetPreloadedEntityBodyLength();
//請求流的總長度
this.totLen = workerRequest.GetTotalEntityBodyLength();
//內容分隔符 如: -----------------------------152733254716788
if (preLen == 0 && workerRequest.IsClientConnected() && workerRequest.HasEntityBody())
{
byte[] buffer = new byte[8192];
preLen = workerRequest.ReadEntityBody(buffer, buffer.Length);
byte[] buf = new byte[preLen];
for (int i = 0; i < buf.Length; i++) buf[i] = buffer[i];
this.perBodyBytes = buf;
}
else
this.perBodyBytes = workerRequest.GetPreloadedEntityBody();
this.headerBytes = this.GetBoundaryBytes(Encoding.UTF8.GetBytes(workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType)));
//請求流尾部分隔符 如: -----------------------------152733254716788--
this.contentEnd = new byte[this.headerBytes.Length + 2];
this.headerBytes.CopyTo(this.contentEnd, 0);
this.contentEnd[this.headerBytes.Length] = 45;
this.contentEnd[this.headerBytes.Length + 1] = 45;
//當前流中第一個文件分隔符的位置
int fHeaderPosition = perBodyBytes.Indexof(fileNameHeader);
//嘗試在已讀取到的流中找文件尾位置
this.fEndPosition = perBodyBytes.Indexof(contentEnd);
if (fHeaderPosition > -1)
{
//先找到文件名
IList<byte> bufList = new List<byte>();
int i = fHeaderPosition + fileNameHeader.Length;
while (i < perBodyBytes.Length)
{
if (perBodyBytes[i] == 34) break;
bufList.Add(perBodyBytes[i]);
i++;
}
this.FileName = Encoding.UTF8.GetString(bufList.ToArray());//file name
this.fPosition = perBodyBytes.Indexof(wrapBytes, i) + 4;//當前流中此文件的開始位置
this.FileLength = this.totLen - this.fPosition;
}
}