Пример #1
0
        public async Task <ActionResult> Index()
        {
            var client = RentalsHttpClient.GetClient();

            HttpResponseMessage response = await client.GetAsync("api/hello");

            if (response.IsSuccessStatusCode)
            {
                string responseString = await response.Content.ReadAsStringAsync();

                ViewBag.HelloResponse = responseString;
            }
            else
            {
                Content("An error occurred.");
            }

            return(View());
        }
Пример #2
0
        public async Task <string> GetText()
        {
            var    client         = RentalsHttpClient.GetClient();
            string responseString = String.Empty;

            await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false);

            HttpResponseMessage response = await client.GetAsync("api/hello");

            if (response.IsSuccessStatusCode)
            {
                responseString = await response.Content.ReadAsStringAsync();
            }
            else
            {
                responseString = "An error occurred.";
            }

            return(responseString);
        }