System.Net.Http

Namespace: System.Net.Http

Provides classes for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. This namespace is a fundamental part of .NET for interacting with web services and APIs over HTTP.

Core Classes

HttpClient

public class HttpClient : IDisposable

Sends HTTP requests and receives responses from a resource identified by a URI. This is the primary class for making HTTP calls.

Key Features:

View Details »

HttpRequestMessage

public class HttpRequestMessage : IDisposable

Represents an HTTP request message.

Used to construct the details of an outgoing HTTP request, including the method, URI, headers, and body.

View Details »

HttpResponseMessage

public class HttpResponseMessage : IDisposable

Represents an HTTP response message received from an HTTP server.

Contains the status code, headers, and content of an HTTP response.

View Details »

HttpContent

public abstract class HttpContent : IDisposable

Represents an HTTP protocol content.

This is an abstract base class. Concrete implementations like StringContent, ByteArrayContent, and StreamContent are used to represent different types of HTTP request/response bodies.

View Details »

Common Implementations of HttpContent

StringContent

public class StringContent : HttpContent

Represents an HTTP request or response body as a string.

View Details »

ByteArrayContent

public class ByteArrayContent : HttpContent

Represents an HTTP request or response body as a byte array.

View Details »

Helper Classes and Enums

HttpMethod

public class HttpMethod

Represents an HTTP method (verb).

Provides static instances for common HTTP methods like GET, POST, PUT, DELETE, etc.

View Details »

HttpStatusCode

public enum HttpStatusCode

Specifies values that define status codes returned by an HTTP server.

Examples include OK (200), NotFound (404), InternalServerError (500).

View Details »

HttpRequestException

public class HttpRequestException : Exception

The exception that is thrown when an error occurs during an asynchronous HTTP request.

View Details »

HttpMessageHandler

public abstract class HttpMessageHandler : IDisposable

An abstract base class for handling HTTP messages. This is used internally by HttpClient and can be extended for custom behavior (e.g., logging, authentication).

View Details »