Ejemplo n.º 1
0
        static async Task RunHelloWorld(string apiBaseUrl, IOutputHandler outputHandler)
        {
            client.BaseAddress = new Uri(apiBaseUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            try
            {
                var apiResponse = await client.GetAsync("api/HelloWorld");

                if (apiResponse.IsSuccessStatusCode)
                {
                    var payload = await apiResponse.Content.ReadAsStringAsync();
                    
                    outputHandler.ProcessOutput(payload);
                }
                else
                {
                    System.Console.WriteLine($"The API returned an unsuccessful response code ({apiResponse.StatusCode}).");
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine($"An error has occurred: {e.Message}");
            }

            System.Console.ReadLine();
        }