Exemplo n.º 1
0
        static AccountResponse GetAccountAsync(string path)
        {
            AccountResponse model  = null;
            var             client = new HttpClient();
            var             task   = client.GetAsync(path)
                                     .ContinueWith((taskwithresponse) =>
            {
                var response   = taskwithresponse.Result;
                var jsonString = response.Content.ReadAsStringAsync();
                jsonString.Wait();
                model = JsonConvert.DeserializeObject <AccountResponse>(jsonString.Result);
            });

            task.Wait();
            return(model);
        }
Exemplo n.º 2
0
        static async Task RunAsync()
        {
                     
            //   client.BaseAddress = new Uri("https://ihab-ock-api.free.beeceptor.com/details");
            client.BaseAddress = new Uri("http://localhost:3001/details");

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                while (true)
                {
                    accts = GetAccountAsync(client.BaseAddress.AbsoluteUri);
                    Console.WriteLine("#of Accounts = {0}", accts.Accounts.Count);
                    Console.WriteLine(accts.Accounts.ToArray()[0].account_number);
                    Console.WriteLine(accts.Accounts.ToArray()[0].customers.ToArray()[0].first_name);

                    System.Threading.Thread.Sleep(60 * 1000);
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            // Console.ReadLine();
        }