static async Task RunAsync() { client.BaseAddress = new Uri("http://localhost:8080/teledon/cazuri"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); String id = "3"; CazCaritabil result = await GetCazAsync("http://localhost:8080/teledon/cazuri/" + id); Console.WriteLine("Am primit {0}", result); Console.WriteLine("get all:"); Console.ReadLine(); var cazuri = await GetCazuriAsync("http://localhost:8080/teledon/cazuri"); foreach (var caz in cazuri) { Console.WriteLine(caz); } Console.WriteLine("add"); Console.ReadLine(); Add("bun", "http://localhost:8080/teledon/cazuri"); Console.ReadLine(); Update("17", "update", "http://localhost:8080/teledon/cazuri"); Delete(); }
static async Task <CazCaritabil> GetCazAsync(string path) { CazCaritabil caz = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { caz = await response.Content.ReadAsAsync <CazCaritabil>(); } return(caz); }
static async void Add(string desrieree, string path) { CazCaritabil c = new CazCaritabil(desrieree); var json = JsonConvert.SerializeObject(c); var data = new StringContent(json, Encoding.UTF8, "application/json"); var url = path; var response = await client.PostAsync(url, data); string result = response.Content.ReadAsStringAsync().Result; }