Exemple #1
0
        public async Task <T> ExecuteWithoutApiResponse <T>(IRequest request)
        {
            var restClient = new RestSharp.Portable.RestClient();

            restClient.BaseUrl = new Uri(request.BaseUrl);


            var restRequest = CreateRequest(request);

            foreach (var par in request.Params)
            {
                restRequest.AddParameter(par.Key, par.Value);
            }
            var uri = restClient.BuildUri(restRequest);

            Debug.WriteLine(uri);

            var response = await restClient.Execute <T>(restRequest);

            var bytes = response.RawBytes;
            var str   = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            var data  = response.Data;

            return(data);
        }
Exemple #2
0
        public async Task <ApiResponse <T> > Execute <T>(IRequest request)
        {
            var restClient = new RestSharp.Portable.RestClient();

            restClient.AddHandler("application/json", new JsonDeserializer());
            restClient.BaseUrl = new Uri(request.BaseUrl);


            var restRequest = CreateRequest(request);
            var uri         = restClient.BuildUri(restRequest);

            Debug.WriteLine(uri);
            try
            {
                var response = await restClient.Execute <ApiResponse <T> >(restRequest);

                var bytes = response.RawBytes;
                var str   = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                var data  = response.Data;
                return(data);
            }
            catch (Exception e)
            {
                throw new ApiException(10000, e.Message);
            }
        }