示例#1
0
        public override async Task <string> GsqlHttpPostStringAsync(string query, string data)
        {
            var request = new RestRequest(query, Method.POST, DataFormat.None);

            request.AddParameter("body", System.Web.HttpUtility.UrlEncode(data, System.Text.Encoding.UTF8), "application/x-www-form-urlencoded", ParameterType.RequestBody);
            IRestResponse response = await GsqlClient.ExecuteAsync(request);

            if (response.ErrorException != null)
            {
                throw response.ErrorException;
            }
            else
            {
                return(response.Content);
            }
        }
示例#2
0
        public override async Task <T2> GsqlHttpPostAsync <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}", GsqlServerUrl.ToString() + query);
            IRestResponse response = await GsqlClient.ExecuteAsync(request);

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

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

            if (response.ErrorException != null)
            {
                throw response.ErrorException;
            }
            else if (!response.IsSuccessful)
            {
                throw new Exception($"HTTP request to GSQL server at {GsqlServerUrl} was not successfule: {response.ErrorMessage}");
            }
            else
            {
                Debug("JSON response: {0}", response.Content);
                return(JsonConvert.DeserializeObject <T>(response.Content));
            }
        }