示例#1
0
        public async Task <MvxDecodedRestResponse <T> > MakeRequestForAsync <T>(MvxRestRequest restRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var decodedResponse = new MvxDecodedRestResponse <T>();

            try {
                var streamResponse = await MakeStreamRequestAsync(restRequest, cancellationToken).ConfigureAwait(false);

                if (streamResponse.StatusCode == HttpStatusCode.BadRequest)
                {
                    decodedResponse.StatusCode = HttpStatusCode.BadRequest;
                }
                else
                {
                    using (var textReader = new StreamReader(streamResponse.Stream)) {
                        var text   = textReader.ReadToEnd();
                        var result = JsonConverterProvider().DeserializeObject <T>(text);

                        decodedResponse.CookieCollection = streamResponse.CookieCollection;
                        decodedResponse.Result           = result;
                        decodedResponse.StatusCode       = streamResponse.StatusCode;
                        decodedResponse.Tag = streamResponse.Tag;
                    }
                }
            } catch {
                decodedResponse.StatusCode = HttpStatusCode.BadRequest;
            }

            return(decodedResponse);
        }
示例#2
0
 public IMvxAbortable MakeRequestFor <T>(MvxRestRequest restRequest, Action <MvxDecodedRestResponse <T> > successAction, Action <Exception> errorAction)
 {
     return(MakeRequest(restRequest, (MvxStreamRestResponse streamResponse) => {
         using (var textReader = new StreamReader(streamResponse.Stream)) {
             var text = textReader.ReadToEnd();
             var result = JsonConverterProvider().DeserializeObject <T>(text);
             var decodedResponse = new MvxDecodedRestResponse <T>
             {
                 CookieCollection = streamResponse.CookieCollection,
                 Result = result,
                 StatusCode = streamResponse.StatusCode,
                 Tag = streamResponse.Tag
             };
             successAction?.Invoke(decodedResponse);
         }
     }, errorAction));
 }