.NET MAUI

Cross-Platform Development with C#

MAUI Networking Tutorials

Explore how to leverage networking capabilities within your .NET MAUI applications. Learn to make HTTP requests, handle responses, and manage network connections efficiently.

Getting Started

Advanced Topics

Code Example: Basic HTTP GET Request

Here's a simple example of how to perform an HTTP GET request to retrieve data:

using System.Net.Http; using System.Threading.Tasks; public class NetworkService { private readonly HttpClient _httpClient; public NetworkService() { _httpClient = new HttpClient(); } public async Task<string> GetDataFromApiAsync(string url) { try { HttpResponseMessage response = await _httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); // Throws if response is not 2xx string responseBody = await response.Content.ReadAsStringAsync(); return responseBody; } catch (HttpRequestException e) { Console.WriteLine($"\nException Caught!"); Console.WriteLine($"Message :{0} ", e.Message); return null; } } }