コード例 #1
0
        public FluentHttpAsyncResult Execute()
        {
            AuthenticateIfRequried();

            var requestUrl = BuildRequestUrl();

            var httpWebHelper = new HttpWebHelper();

            // todo add cookies

            var headers        = GetHeaders().GetHeaderPairs();
            var httpWebRequest = httpWebHelper.CreateHttpWebRequest(requestUrl, GetMethod(), headers, null);

            PrepareHttpWebRequest(httpWebRequest);

            FluentHttpResponse fluentHttpResponse = null;

            httpWebHelper.ResponseReceived +=
                (o, e) =>
            {
                fluentHttpResponse = new FluentHttpResponse(this, e.Response);
                var args = new ResponseHeadersReceivedEventArgs(fluentHttpResponse, e.Exception, null);
                OnResponseHeadersRecived(args);
                e.ResponseSaveStream = fluentHttpResponse.SaveStream;
            };

            var httpWebHelperResult = httpWebHelper.Execute(httpWebRequest, GetBody().Stream);

            return(new FluentHttpAsyncResult(this, fluentHttpResponse, null, null, true, true, false, httpWebHelperResult.Exception, httpWebHelperResult.InnerException));

            /*
             * System.Threading.ManualResetEvent wait = new System.Threading.ManualResetEvent(false);
             * FluentHttpAsyncResult asyncResult = null;
             *
             * ExecuteAsync(ar => { asyncResult = ar; wait.Set(); });
             * wait.WaitOne();
             *
             * if (asyncResult.Exception == null)
             *  return asyncResult;
             *
             * throw asyncResult.Exception;
             */
        }
コード例 #2
0
        public void ExecuteAsync(FluentHttpAsyncCallback callback, object state)
        {
            AuthenticateIfRequried();

            var requestUrl = BuildRequestUrl();

            var httpWebHelper = new HttpWebHelper();

            // todo add cookies

            var headers        = GetHeaders().GetHeaderPairs();
            var httpWebRequest = httpWebHelper.CreateHttpWebRequest(requestUrl, GetMethod(), headers, null);

            PrepareHttpWebRequest(httpWebRequest);

            FluentHttpResponse fluentHttpResponse = null;

            httpWebHelper.ResponseReceived +=
                (o, e) =>
            {
                fluentHttpResponse = new FluentHttpResponse(this, e.Response);
                var args = new ResponseHeadersReceivedEventArgs(fluentHttpResponse, e.Exception, state);
                OnResponseHeadersRecived(args);
                e.ResponseSaveStream = fluentHttpResponse.SaveStream;
            };

            httpWebHelper.ExecuteAsync(httpWebRequest, GetBody().Stream,
                                       ar =>
            {
                if (callback != null)
                {
                    var asyncResult           = (HttpWebHelperResult)ar;
                    var fluentHttpAsyncResult = new FluentHttpAsyncResult(this, fluentHttpResponse, state, null, ar.CompletedSynchronously, true, false, asyncResult.Exception, asyncResult.InnerException);
                    callback(fluentHttpAsyncResult);
                }
            }, null);
        }
コード例 #3
0
 public static string AddStartingSlashInNotPresent(string input)
 {
     return(HttpWebHelper.AddStartingSlashIfNotPresent(input));
 }
コード例 #4
0
 public string BuildRequestUrl()
 {
     return(HttpWebHelper.BuildRequestUrl(GetBaseUrl(), GetResourcePath(), GetQueryStrings().GetQueryStringPairs()));
 }