示例#1
0
        public override async Task <T> RestHttpGetAsync <T>(string query)
        {
            var request = new RestRequest(query, Method.GET);

            Debug("HTTP GET:{0}", RestServerUrl.ToString() + query);
            IRestResponse response = await RestClient.ExecuteAsync(request);

            if (response.ErrorException != null)
            {
                throw response.ErrorException;
            }
            else
            {
                Debug("JSON response: {0}", response.Content);
                return(JsonConvert.DeserializeObject <T>(response.Content));
            }
        }
示例#2
0
        public override async Task <T2> RestHttpPostAsync <T1, T2>(string query, T1 data)
        {
            var request = new RestRequest(query, Method.POST, DataFormat.Json);

            request.AddHeader("Accept", "application/json");
            request.AddParameter("application/json", JsonConvert.SerializeObject(data), ParameterType.RequestBody);
            Debug("HTTP POST:{0}", RestServerUrl.ToString() + query);
            IRestResponse response = await RestClient.ExecuteAsync(request);

            if (response.ErrorException != null)
            {
                throw response.ErrorException;
            }
            else
            {
                Debug("JSON response: {0}", response.Content);
                return(JsonConvert.DeserializeObject <T2>(response.Content));
            }
        }