本文整理汇总了C#中System.Net.WebConnectionStream.ForceCompletion方法的典型用法代码示例。如果您正苦于以下问题:C# WebConnectionStream.ForceCompletion方法的具体用法?C# WebConnectionStream.ForceCompletion怎么用?C# WebConnectionStream.ForceCompletion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebConnectionStream
的用法示例。
在下文中一共展示了WebConnectionStream.ForceCompletion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDone
static void ReadDone (IAsyncResult result)
{
WebConnection cnc = (WebConnection) result.AsyncState;
WebConnectionData data = cnc.Data;
Stream ns = cnc.nstream;
if (ns == null) {
cnc.Close (true);
return;
}
int nread = -1;
try {
nread = ns.EndRead (result);
} catch (ObjectDisposedException) {
return;
} catch (Exception e) {
if (e.InnerException is ObjectDisposedException)
return;
cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "ReadDone1");
return;
}
if (nread == 0) {
cnc.HandleError (WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
return;
}
if (nread < 0) {
cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadDone3");
return;
}
int pos = -1;
nread += cnc.position;
if (cnc.readState == ReadState.None) {
Exception exc = null;
try {
pos = cnc.GetResponse (cnc.buffer, nread);
} catch (Exception e) {
exc = e;
}
if (exc != null || pos == -1) {
cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, exc, "ReadDone4");
return;
}
}
if (cnc.readState != ReadState.Content) {
int est = nread * 2;
int max = (est < cnc.buffer.Length) ? cnc.buffer.Length : est;
byte [] newBuffer = new byte [max];
Buffer.BlockCopy (cnc.buffer, 0, newBuffer, 0, nread);
cnc.buffer = newBuffer;
cnc.position = nread;
cnc.readState = ReadState.None;
InitRead (cnc);
return;
}
cnc.position = 0;
WebConnectionStream stream = new WebConnectionStream (cnc);
bool expect_content = ExpectContent (data.StatusCode, data.request.Method);
string tencoding = null;
if (expect_content)
tencoding = data.Headers ["Transfer-Encoding"];
cnc.chunkedRead = (tencoding != null && tencoding.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
if (!cnc.chunkedRead) {
stream.ReadBuffer = cnc.buffer;
stream.ReadBufferOffset = pos;
stream.ReadBufferSize = nread;
try {
stream.CheckResponseInBuffer ();
} catch (Exception e) {
cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "ReadDone7");
}
} else if (cnc.chunkStream == null) {
try {
cnc.chunkStream = new ChunkStream (cnc.buffer, pos, nread, data.Headers);
} catch (Exception e) {
cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone5");
return;
}
} else {
cnc.chunkStream.ResetBuffer ();
try {
cnc.chunkStream.Write (cnc.buffer, pos, nread);
} catch (Exception e) {
cnc.HandleError (WebExceptionStatus.ServerProtocolViolation, e, "ReadDone6");
return;
}
}
data.stream = stream;
if (!expect_content)
stream.ForceCompletion ();
//.........这里部分代码省略.........