Created
December 14, 2020 06:11
-
-
Save bethkrish/64831126c3713f32fdb3149bbd47691a to your computer and use it in GitHub Desktop.
Example API Client in C# - Console Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
namespace HTTPCall | |
{ | |
class Program | |
{ | |
static readonly HttpClient client = new HttpClient(); | |
static async System.Threading.Tasks.Task Main(string[] args) | |
{ | |
try | |
{ | |
HttpResponseMessage response = await client.GetAsync("https://reqres.in/api/users?page=2"); | |
response.EnsureSuccessStatusCode(); | |
string responseBody = await response.Content.ReadAsStringAsync(); | |
Console.WriteLine(responseBody); | |
} | |
catch (HttpRequestException e) | |
{ | |
Console.WriteLine("\nException Caught!"); | |
Console.WriteLine("Message :{0} ", e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment