本文整理汇总了C#中System.Web.HttpResponse.SetContentLength方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.SetContentLength方法的具体用法?C# HttpResponse.SetContentLength怎么用?C# HttpResponse.SetContentLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.SetContentLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessPostRequest
private static void ProcessPostRequest(HttpRequest request, HttpResponse response, HttpSessionState session)
{
response.ContentType = "application/octet-stream";
var memoryStream = new MemoryStream();
var output = new DataOutputStream(memoryStream);
try
{
var input = new DataInputStream(request.InputStream);
var version = request.Headers["version"];
if (version != null)
{
if (!HttpProcessor.PROTOCOL_VERSION.Equals(version, StringComparison.Ordinal))
throw new IOException(String.Format(
CultureInfo.CurrentCulture,
Resources.IO_InvalidProtocolVersion,
version,
HttpProcessor.PROTOCOL_VERSION));
}
if (input.ReadInt16() == HttpProcessor.INVOCATION_CODE)
InvokeMethod(session, input.ReadInt32(), input, output);
input.Close();
}
catch (Exception e)
{
if (output == null)
output = new DataOutputStream(response.OutputStream);
output.WriteInt16(HttpProcessor.RESULT_EXCEPTION);
Debug.WriteLine(e.StackTrace);
output.WriteString(e.ToString());
}
response.SetContentLength(memoryStream.Length);
try
{
var data = new Byte[memoryStream.Length];
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.Read(data, 0, data.Length);
response.OutputStream.Write(data, 0, data.Length);
}
finally
{
if (output != null)
output.Close();
response.OutputStream.Close();
}
}