simulate ten calls to api that return http code 418 in csharp

main.cs
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        int numCalls = 10;
        string apiUrl = "https://httpstat.us/418"; // returns 418 HTTP status code
        
        using (var httpClient = new HttpClient())
        {
            for (int i = 1; i <= numCalls; i++)
            {
                var response = await httpClient.GetAsync(apiUrl);
                Console.WriteLine($"Call {i}: {response.StatusCode}");
            }
        }
    }
}
542 chars
22 lines

This C# code uses HttpClient to make numCalls requests to an API endpoint that would always return HTTP 418 status code. The async and await keywords are used to allow other actions to continue while the calls to the API are being made. The loop prints out the HTTP status code of each returned response in the console.

gistlibby LogSnag