Exemple #1
0
 protected void OnResponseReceived(ResponseReceivedEventArgs args)
 {
     if (ResponseReceived != null)
     {
         ResponseReceived(this, args);
     }
 }
Exemple #2
0
        private void RequestCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state)
        {
            Stream           requestStream   = null;
            Exception        exception       = null;
            IHttpWebResponse httpWebResponse = null;

            try
            {
                requestStream = httpWebRequest.EndGetRequestStream(asyncResult);
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception       = webException;
            }
            finally
            {
                if (exception == null)
                {
                    // we got the stream, so copy to the stream
                    CopyRequestStream(httpWebRequest, requestBody, requestStream, callback, state);
                }
                else
                {
                    // there was an error
                    if (httpWebResponse == null)
                    {
                        if (callback != null)
                        {
                            callback(new HttpWebHelperResult(httpWebRequest, null, exception, null, false, false, null, state));
                        }
                    }
                    else
                    {
                        var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state);
                        OnResponseReceived(args);
                        ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state);
                    }
                }
            }
        }
Exemple #3
0
        private HttpWebHelperResult WriteAndGetReponse(IHttpWebRequest httpWebRequest, Stream requestBody)
        {
            Stream              requestStream   = null;
            Exception           exception       = null;
            IHttpWebResponse    httpWebResponse = null;
            HttpWebHelperResult result;

            try
            {
                requestStream = httpWebRequest.GetRequestStream();
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception       = webException;
            }
            finally
            {
                if (exception == null)
                {
                    // we got the stream, so copy to the stream
                    result = CopyRequestStream(httpWebRequest, requestBody, requestStream);
                }
                else
                {
                    // there was an error
                    if (httpWebResponse == null)
                    {
                        result = new HttpWebHelperResult(httpWebRequest, null, exception, null, false, true, null, null);
                    }
                    else
                    {
                        var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null);
                        OnResponseReceived(args);
                        result = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream);
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        private void ResponseCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state)
        {
            IHttpWebResponse httpWebResponse = null;
            Exception        exception       = null;

            try
            {
                httpWebResponse = httpWebRequest.EndGetResponse(asyncResult);
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception       = webException;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (httpWebResponse != null)
                {
                    var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state);
                    OnResponseReceived(args);
                    ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state);
                }
                else
                {
                    if (callback != null)
                    {
                        callback(new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, false, null, state));
                    }
                }
            }
        }
Exemple #5
0
        private HttpWebHelperResult GetResponse(IHttpWebRequest httpWebRequest, Stream requestBody)
        {
            IHttpWebResponse    httpWebResponse          = null;
            Exception           exception                = null;
            HttpWebHelperResult httpWebHelperAsyncResult = null;

            try
            {
                httpWebResponse = httpWebRequest.GetResponse();
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception       = webException;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (httpWebResponse != null)
                {
                    var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null);
                    OnResponseReceived(args);
                    httpWebHelperAsyncResult = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream);
                }
                else
                {
                    httpWebHelperAsyncResult = new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, true, null, null);
                }
            }

            return(httpWebHelperAsyncResult);
        }
        private HttpWebHelperResult WriteAndGetReponse(IHttpWebRequest httpWebRequest, Stream requestBody)
        {
            Stream requestStream = null;
            Exception exception = null;
            IHttpWebResponse httpWebResponse = null;
            HttpWebHelperResult result;

            try
            {
                requestStream = httpWebRequest.GetRequestStream();
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception = webException;
            }
            finally
            {
                if (exception == null)
                {
                    // we got the stream, so copy to the stream
                    result = CopyRequestStream(httpWebRequest, requestBody, requestStream);
                }
                else
                {
                    // there was an error
                    if (httpWebResponse == null)
                    {
                        result = new HttpWebHelperResult(httpWebRequest, null, exception, null, false, true, null, null);
                    }
                    else
                    {
                        var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null);
                        OnResponseReceived(args);
                        result = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream);
                    }
                }
            }

            return result;
        }
        private HttpWebHelperResult GetResponse(IHttpWebRequest httpWebRequest, Stream requestBody)
        {
            IHttpWebResponse httpWebResponse = null;
            Exception exception = null;
            HttpWebHelperResult httpWebHelperAsyncResult = null;

            try
            {
                httpWebResponse = httpWebRequest.GetResponse();
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception = webException;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (httpWebResponse != null)
                {
                    var args = new ResponseReceivedEventArgs(httpWebResponse, exception, null);
                    OnResponseReceived(args);
                    httpWebHelperAsyncResult = ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream);
                }
                else
                {
                    httpWebHelperAsyncResult = new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, true, null, null);
                }
            }

            return httpWebHelperAsyncResult;
        }
        private void ResponseCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state)
        {
            IHttpWebResponse httpWebResponse = null;
            Exception exception = null;

            try
            {
                httpWebResponse = httpWebRequest.EndGetResponse(asyncResult);
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception = webException;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (httpWebResponse != null)
                {
                    var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state);
                    OnResponseReceived(args);
                    ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state);
                }
                else
                {
                    if (callback != null)
                        callback(new HttpWebHelperResult(httpWebRequest, httpWebResponse, exception, null, false, false, null, state));
                }
            }
        }
        private void RequestCallback(IAsyncResult asyncResult, IHttpWebRequest httpWebRequest, Stream requestBody, AsyncCallback callback, object state)
        {
            Stream requestStream = null;
            Exception exception = null;
            IHttpWebResponse httpWebResponse = null;

            try
            {
                requestStream = httpWebRequest.EndGetRequestStream(asyncResult);
            }
            catch (WebException ex)
            {
                var webException = new WebExceptionWrapper(ex);
                httpWebResponse = webException.GetResponse();
                exception = webException;
            }
            finally
            {
                if (exception == null)
                {
                    // we got the stream, so copy to the stream
                    CopyRequestStream(httpWebRequest, requestBody, requestStream, callback, state);
                }
                else
                {
                    // there was an error
                    if (httpWebResponse == null)
                    {
                        if (callback != null)
                            callback(new HttpWebHelperResult(httpWebRequest, null, exception, null, false, false, null, state));
                    }
                    else
                    {
                        var args = new ResponseReceivedEventArgs(httpWebResponse, exception, state);
                        OnResponseReceived(args);
                        ReadResponseStream(httpWebRequest, httpWebResponse, exception, args.ResponseSaveStream, callback, state);
                    }
                }
            }
        }
 protected void OnResponseReceived(ResponseReceivedEventArgs args)
 {
     if (ResponseReceived != null)
     {
         ResponseReceived(this, args);
     }
 }