.NET Web Fundamentals

Web APIs Overview

These APIs provide the building blocks for creating robust, high‑performance web applications with .NET. Explore the most commonly used classes, methods, and patterns.

HttpClient

A modern, async‑based HTTP client for sending requests and receiving responses.

using var client = new HttpClient();
var response = await client.GetAsync("https://api.example.com/data");
var content = await response.Content.ReadAsStringAsync();

HttpWebRequest / HttpWebResponse

Legacy API for fine‑grained control over HTTP requests.

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using var response = (HttpWebResponse)request.GetResponse();
using var stream = response.GetResponseStream();

WebClient

Simple API for quick uploads and downloads.

using var client = new WebClient();
string data = client.DownloadString("https://example.com");

Socket

Low‑level networking for custom protocols.

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse("127.0.0.1"), 8080);
byte[] buffer = Encoding.UTF8.GetBytes("Hello");

Resources