예제 #1
0
        protected virtual void ExecuteRequestWithBody(HttpWebRequest request)
        {
            request.BeginGetRequestStream(new AsyncCallback((IAsyncResult callbackResult) =>
            {
                HttpWebRequest tmprequest = (HttpWebRequest)callbackResult.AsyncState;

                Go(body.GetBody(), tmprequest.EndGetRequestStream(callbackResult));

                tmprequest.BeginGetResponse(ProcessCallback(action.Success, action.Fail), tmprequest);
            }), request);
        }
예제 #2
0
        protected virtual void ExecuteRequestWithBody(HttpWebRequest request)
        {
            request.BeginGetRequestStream(new AsyncCallback((IAsyncResult callbackResult) =>
            {
                HttpWebRequest tmprequest = (HttpWebRequest)callbackResult.AsyncState;

                ProgressCallbackHelper copy = body.GetBody().CopyToProgress(tmprequest.EndGetRequestStream(callbackResult), null);
                copy.ProgressChanged       += (bytesSent, totalBytes) => { body.OnProgressChange(bytesSent, totalBytes); };
                copy.Completed += (totalBytes) => { body.OnCompleted(totalBytes); };
                copy.Go();

                // Start the asynchronous operation to get the response
                tmprequest.BeginGetResponse(ProcessCallback(action.Success, action.Fail), tmprequest);
            }), request);
        }
예제 #3
0
        private RequestData MakeRealTimeRequest()
        {
            Stream stream = null;

            try
            {
                HttpWebRequest request = CreateNewRequest();

                if (method == HttpVerb.Get || method == HttpVerb.Head)
                {
                    stream = (request.GetResponse()).GetResponseStream();
                }
                else
                {
                    if (request.ContentType == null)
                    {
                        request.ContentType = body.GetContentType();
                    }

                    using (Stream myRequestStream = request.GetRequestStream())
                    {
                        var    contentLength = body.GetBody().Length;
                        byte[] bodyBytes     = new byte[contentLength];
                        body.GetBody().Read(bodyBytes, 0, bodyBytes.Length);
                        body.GetBody().Seek(0, SeekOrigin.Begin);

                        int maxLength = 500;
                        int ec;
                        for (int i = 0; i < contentLength; i += maxLength)
                        {
                            if (i + maxLength < contentLength)
                            {
                                ec = 500;
                            }
                            else
                            {
                                ec = (int)contentLength - i;
                            }
                            myRequestStream.Write(bodyBytes, i, ec);
                        }
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                        stream = response.GetResponseStream();

                        //using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        //{
                        //    stream = response.GetResponseStream();
                        //}
                    }
                }
            }
            catch (WebException webEx)
            {
                if (action.Fail != null)
                {
                    action.Fail(webEx);
                }
                else
                {
                    throw webEx;
                }
            }
            return(new RequestData(stream));
        }