private void WriteRequestStream(IAsyncResult result) { var cx = this; Stream stm = null; StreamWriteContext scx = null; try { var req = result.AsyncState as HttpWebRequest; stm = req.EndGetRequestStream(result); scx = new StreamWriteContext(stm, this.RequestBufferSize); scx.Uploading += (o, e) => this.OnUploading(e); scx.Write(_Command.BodyStream); stm.Dispose(); stm = null; req.BeginGetResponse(this.GetResponse, req); } catch (Exception ex) { this.OnError(ex); } finally { if (stm != null) { stm.Dispose(); } } }
public HttpWebResponse GetHttpWebResponse(HttpRequestCommand command) { HttpWebRequest req = this.CreateRequest(command); StreamWriteContext scx = null; if (command.BodyStream != null && command.IsSendBodyStream == true) { //Request body //req.ContentLength = command.BodyStream.Length; if (command.GetBodyLength() > 0) { using (var stm = req.GetRequestStream()) { scx = new StreamWriteContext(stm, this.RequestBufferSize); scx.Uploading += (o, e) => this.OnUploading(e); scx.Write(command.BodyStream); stm.Dispose(); } } } return(req.GetResponse() as HttpWebResponse); }