Exemple #1
0
        private void HandleGetRequestStream(IAsyncResult result)
        {
            AsyncState state = (AsyncState)result.AsyncState;

            try
            {
                using (Stream requestStream = state.Request.EndGetRequestStream(result))
                {
                    WriteBody(requestStream, state.Request, state.IncludeBody);
                }

                ApplyDataSentInterceptors(state.Request);

                state.Request.BeginGetResponse(HandleResponse, state);
            }
            catch (WebException ex)
            {
                Response response = new Response((HttpWebResponse)ex.Response, Session, state.RetryLevel);
                HandleWebExceptionResult exResult = HandleWebException(ex, state.Url, state.Method, state.IncludeBody, state.RequestModifier, state.RetryLevel);
                if (!exResult.Retried)
                {
                    if (ex.Status != WebExceptionStatus.RequestCanceled)
                    {
                        TryCallErrorCallback(ex, response);
                    }
                    TryCallCompleteCallback(response);
                }
            }
            finally
            {
                CurrentAsyncRequest = null;
            }
        }
Exemple #2
0
        private void HandleResponse(IAsyncResult result)
        {
            AsyncState state = (AsyncState)result.AsyncState;

            try
            {
                HttpWebResponse response = state.Request.EndGetResponse(result) as HttpWebResponse;
                using (Response r = HandleResponse(response, state.Method, state.IncludeBody, state.RequestModifier, state.RetryLevel))
                {
                    if (r != null)
                    {
                        TryCallResponseCallback(r);
                        TryCallCompleteCallback(r);
                    }
                }
            }
            catch (WebException ex)
            {
                Response response = new Response((HttpWebResponse)ex.Response, Session, state.RetryLevel);
                HandleWebExceptionResult exResult = HandleWebException(ex, state.Url, state.Method, state.IncludeBody, state.RequestModifier, state.RetryLevel);
                if (!exResult.Retried)
                {
                    if (ex.Status != WebExceptionStatus.RequestCanceled)
                    {
                        TryCallErrorCallback(ex, response);
                    }
                    TryCallCompleteCallback(response);
                }
            }
            finally
            {
                CurrentAsyncRequest = null;
            }
        }
Exemple #3
0
 protected virtual Response DoRequest(Uri url, string method, bool includeBody, Action <HttpWebRequest> requestModifier, int retryLevel = 0)
 {
     try
     {
         HttpWebRequest request = SetupRequest(url, method, includeBody, requestModifier);
         WriteBody(null, request, includeBody);
         ApplyDataSentInterceptors(request);
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         return(HandleResponse(response, method, includeBody, requestModifier, retryLevel));
     }
     catch (WebException ex)
     {
         HandleWebExceptionResult result = HandleWebException(ex, url, method, includeBody, requestModifier, retryLevel);
         if (!result.Retried)
         {
             throw;
         }
         return(result.Response);
     }
 }