예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        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.BodyStream.Length > 0)
                {
                    using (var stm = req.GetRequestStream())
                    {
                        if (this.RequestBufferSize.HasValue == true)
                        {
                            scx = new StreamWriteContext(stm, this.RequestBufferSize.Value);
                        }
                        else
                        {
                            scx = new StreamWriteContext(stm);
                        }
                        scx.Uploading += (o, e) => this.OnUploading(e);
                        scx.Write(command.BodyStream);
                        stm.Dispose();
                    }
                }
            }
            return(req.GetResponse() as HttpWebResponse);
        }
예제 #2
0
        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();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        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.BodyStream.Length > 0)
                {
                    using (var stm = req.GetRequestStream())
                    {
                        if (this.RequestBufferSize.HasValue == true)
                        {
                            scx = new StreamWriteContext(stm, this.RequestBufferSize.Value);
                        }
                        else
                        {
                            scx = new StreamWriteContext(stm);
                        }
                        scx.Uploading += (o, e) => this.OnUploading(e);
                        scx.Write(command.BodyStream);
                        stm.Dispose();
                    }
                }
            }
            return req.GetResponse() as HttpWebResponse;
        }
예제 #4
0
 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);
         if (this.RequestBufferSize.HasValue == true)
         {
             scx = new StreamWriteContext(stm, this.RequestBufferSize.Value);
         }
         else
         {
             scx = new StreamWriteContext(stm);
         }
         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();
         }
     }
 }