HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync("https://api.example.com/data"); string responseBody = await response.Content.ReadAsStringAsync();
HttpClient client = new HttpClient(); var content = new StringContent("{\"name\":\"John Doe\", \"age\":30}", Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://api.example.com/users", content);
HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer yourtoken"); HttpResponseMessage response = await client.GetAsync("https://api.example.com/data");This example adds a custom Authorization header to the request before sending it to the server. Package library: System.Net.Http (included in the .NET Framework and .NET Core)