コード例 #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
ファイル: AsyncHttpContext.cs プロジェクト: fengweijp/higlabo
 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();
         }
     }
 }