protected virtual void ProcessResponse(MvxRestRequest restRequest, HttpWebRequest httpRequest, Action <MvxRestResponse> successAction, Action <Exception> errorAction)
        {
            httpRequest.BeginGetResponse(result =>
                                         TryCatch(() =>
            {
                var response = (HttpWebResponse)httpRequest.EndGetResponse(result);

                var code = response.StatusCode;

                var restResponse = new MvxRestResponse
                {
                    CookieCollection = response.Cookies,
                    Tag        = restRequest.Tag,
                    StatusCode = code
                };
                successAction?.Invoke(restResponse);
            }, errorAction), null);
        }
示例#2
0
        protected virtual void ProcessStreamResponse(MvxRestRequest restRequest, HttpWebRequest httpRequest, Action <MvxStreamRestResponse> successAction)
        {
            httpRequest.BeginGetResponse(result =>
            {
                var response = (HttpWebResponse)httpRequest.EndGetResponse(result);

                var code           = response.StatusCode;
                var responseStream = response.GetResponseStream();
                var restResponse   = new MvxStreamRestResponse
                {
                    CookieCollection = response.Cookies,
                    Stream           = responseStream,
                    Tag        = restRequest.Tag,
                    StatusCode = code
                };
                successAction?.Invoke(restResponse);
            }, null);
        }
        public IMvxAbortable MakeRequest(MvxRestRequest restRequest, Action <MvxRestResponse> successAction, Action <Exception> errorAction)
        {
            HttpWebRequest httpRequest = null;

            TryCatch(() =>
            {
                httpRequest = BuildHttpRequest(restRequest);

                Action processResponse = () => ProcessResponse(restRequest, httpRequest, successAction, errorAction);
                if (restRequest.NeedsRequestStream)
                {
                    ProcessRequestThen(restRequest, httpRequest, processResponse, errorAction);
                }
                else
                {
                    processResponse();
                }
            }, errorAction);

            return(httpRequest != null ? new MvxRestRequestAsyncHandle(httpRequest) : null);
        }
 protected virtual void SetPlatformSpecificProperties(MvxRestRequest restRequest, HttpWebRequest httpRequest)
 {
     // do nothing by default
 }
 protected virtual HttpWebRequest CreateHttpWebRequest(MvxRestRequest restRequest)
 {
     return((HttpWebRequest)WebRequest.Create(restRequest.Uri));
 }
 protected virtual void SetMethod(MvxRestRequest restRequest, HttpWebRequest httpRequest)
 {
     httpRequest.Method = restRequest.Verb;
 }