本文整理汇总了C#中System.Web.HttpWorkerRequest.HasEntityBody方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWorkerRequest.HasEntityBody方法的具体用法?C# HttpWorkerRequest.HasEntityBody怎么用?C# HttpWorkerRequest.HasEntityBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpWorkerRequest
的用法示例。
在下文中一共展示了HttpWorkerRequest.HasEntityBody方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: GetEncodingFromHeaders
public static Encoding GetEncodingFromHeaders(HttpWorkerRequest workerRequest)
{
if (workerRequest == null)
throw new ArgumentNullException("workerRequest");
string userAgent = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderUserAgent);
if (userAgent != null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(userAgent, "UP"))
{
string text = workerRequest.GetUnknownRequestHeader("x-up-devcap-post-charset");
if (!string.IsNullOrEmpty(text))
{
try
{
return Encoding.GetEncoding(text);
}
catch
{
}
}
}
if (!workerRequest.HasEntityBody())
{
return null;
}
string contentType = workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);
if (contentType == null)
{
return null;
}
string attributeFromHeader = GetAttributeFromHeader(contentType, "charset");
if (attributeFromHeader == null)
{
return null;
}
Encoding result = null;
try
{
result = Encoding.GetEncoding(attributeFromHeader);
}
catch
{
}
return result;
}