Beispiel #1
0
        protected static async Task DeleteAsync(string url)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = SimulacronManager.BaseAddress;
                var response = await client.DeleteAsync(url).ConfigureAwait(false);

                await SimulacronBase.EnsureSuccessStatusCode(response).ConfigureAwait(false);
            }
        }
Beispiel #2
0
        protected static async Task <T> Get <T>(string url)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = SimulacronManager.BaseAddress;
                var response = await client.GetAsync(url).ConfigureAwait(false);

                await SimulacronBase.EnsureSuccessStatusCode(response).ConfigureAwait(false);

                var dataStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(JsonConvert.DeserializeObject <T>(dataStr));
            }
        }
Beispiel #3
0
        protected static async Task <JObject> Post(string url, object body)
        {
            var bodyStr = SimulacronBase.GetJsonFromObject(body);
            var content = new StringContent(bodyStr, Encoding.UTF8, "application/json");

            using (var client = new HttpClient())
            {
                client.BaseAddress = SimulacronManager.BaseAddress;
                var response = await client.PostAsync(url, content).ConfigureAwait(false);

                await SimulacronBase.EnsureSuccessStatusCode(response).ConfigureAwait(false);

                var dataStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(JObject.Parse(dataStr));
            }
        }