Represents the fluent http async result.
Inheritance: IAsyncResult
Example #1
0
        private static string PeelOutGistHtmlUrl(FluentHttpAsyncResult response)
        {
            response.Response.SaveStream.Seek(0, SeekOrigin.Begin);
            var gistJson = FluentHttpRequest.ToString(response.Response.SaveStream);

            dynamic gist = JObject.Parse(gistJson);

            return (string)gist.html_url;
        }
Example #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);
        }