public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
{
if (Aborted)
throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled);
bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" ||
method == "TRACE");
if (method == null || !send)
throw new ProtocolViolationException ("Cannot send data when method is: " + method);
if (contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive)
throw new ProtocolViolationException ("Content-Length not set");
string transferEncoding = TransferEncoding;
if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "")
throw new ProtocolViolationException ("SendChunked should be true.");
lock (locker)
{
if (asyncWrite != null) {
throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
"method while a previous call is still in progress.");
}
asyncWrite = new WebAsyncResult (this, callback, state);
initialMethod = method;
if (haveRequest) {
if (writeStream != null) {
asyncWrite.SetCompleted (true, writeStream);
asyncWrite.DoCallback ();
return asyncWrite;
}
}
gotRequestStream = true;
WebAsyncResult result = asyncWrite;
if (!requestSent) {
requestSent = true;
redirects = 0;
servicePoint = GetServicePoint ();
abortHandler = servicePoint.SendRequest (this, connectionGroup);
}
return result;
}
}