示例#1
0
        /// <summary>
        /// Gets the request stream
        /// </summary>
        /// <returns>The request stream</returns>
        /// <param name="contentlength">The content length to use</param>
        public Stream GetRequestStream(long contentlength = -1)
        {
            // Prevent in-memory buffering causing out-of-memory issues
            if (this.m_request is HttpWebRequest request)
            {
                if (contentlength >= 0)
                {
                    request.ContentLength = contentlength;
                }
                if (request.ContentLength >= 0)
                {
                    request.AllowWriteStreamBuffering = false;
                }
            }

            if (m_state == RequestStates.GetRequest)
            {
                return((Stream)m_asyncRequest.GetResponseOrStream());
            }

            if (m_state != RequestStates.Created)
            {
                throw new InvalidOperationException();
            }

            m_asyncRequest = new AsyncWrapper(this, true);
            m_state        = RequestStates.GetRequest;

            return(TrySetTimeout((Stream)m_asyncRequest.GetResponseOrStream(), m_activity_timeout));
        }
示例#2
0
        /// <summary>
        /// Gets the request stream
        /// </summary>
        /// <returns>The request stream</returns>
        public Stream GetRequestStream()
        {
            if (m_state == RequestStates.GetRequest)
            {
                return((Stream)m_asyncRequest.GetResponseOrStream());
            }

            if (m_state != RequestStates.Created)
            {
                throw new InvalidOperationException();
            }

            m_asyncRequest = new AsyncWrapper(this, true);
            m_state        = RequestStates.GetRequest;

            return(TrySetTimeout((Stream)m_asyncRequest.GetResponseOrStream(), m_activity_timeout));
        }
示例#3
0
        /// <summary>
        /// Gets the response object
        /// </summary>
        /// <returns>The web response</returns>
        public WebResponse GetResponse()
        {
            if (m_state == RequestStates.GetResponse)
            {
                return((WebResponse)m_asyncResponse.GetResponseOrStream());
            }

            if (m_state == RequestStates.Done)
            {
                throw new InvalidOperationException();
            }

            m_asyncRequest  = null;
            m_asyncResponse = new AsyncWrapper(this, false);
            m_state         = RequestStates.GetResponse;

            return((WebResponse)m_asyncResponse.GetResponseOrStream());
        }
示例#4
0
        /// <summary>
        /// Gets the request stream
        /// </summary>
        /// <returns>The request stream</returns>
        public Stream GetRequestStream()
        {
            if (m_state == RequestStates.GetRequest)
            {
                return((Stream)m_asyncRequest.GetResponseOrStream());
            }

            if (m_state != RequestStates.Created)
            {
                throw new InvalidOperationException();
            }

            m_asyncRequest = new AsyncWrapper(this, true);
            m_state        = RequestStates.GetRequest;

            var s = (Stream)m_asyncRequest.GetResponseOrStream();

            try { s.WriteTimeout = m_activity_timeout; }
            catch { }

            return(s);
        }
示例#5
0
        /// <summary>
        /// Gets the response object
        /// </summary>
        /// <returns>The web response</returns>
        public WebResponse GetResponse()
        {
            if (m_state == RequestStates.GetResponse)
                return (WebResponse)m_asyncResponse.GetResponseOrStream();

            if (m_state == RequestStates.Done)
                throw new InvalidOperationException();

            m_asyncRequest = null;
            m_asyncResponse = new AsyncWrapper(this, false);
            m_state = RequestStates.GetResponse;

            return (WebResponse)m_asyncResponse.GetResponseOrStream();
        }
示例#6
0
        /// <summary>
        /// Gets the request stream
        /// </summary>
        /// <returns>The request stream</returns>
        public Stream GetRequestStream()
        {
            if (m_state == RequestStates.GetRequest)
                return (Stream)m_asyncRequest.GetResponseOrStream();

            if (m_state != RequestStates.Created)
                throw new InvalidOperationException();

            m_asyncRequest = new AsyncWrapper(this, true);
            m_state = RequestStates.GetRequest;

			return TrySetTimeout((Stream)m_asyncRequest.GetResponseOrStream(), m_activity_timeout);
        }
示例#7
0
        /// <summary>
        /// Gets the request stream
        /// </summary>
        /// <returns>The request stream</returns>
        public Stream GetRequestStream()
        {
            if (m_state == RequestStates.GetRequest)
                return (Stream)m_asyncRequest.GetResponseOrStream();

            if (m_state != RequestStates.Created)
                throw new InvalidOperationException();

            m_asyncRequest = new AsyncWrapper(this, true);
            m_state = RequestStates.GetRequest;

            var s = (Stream)m_asyncRequest.GetResponseOrStream();

            try { s.WriteTimeout = m_activity_timeout; }
            catch { }

            return s;
        }