System.Net.Http
System.Net.HttpProvides 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 : IDisposableSends HTTP requests and receives responses from a resource identified by a URI. This is the primary class for making HTTP calls.
Key Features:
- Efficient connection pooling.
- Support for various HTTP methods (GET, POST, PUT, DELETE, etc.).
- Customizable request headers and content.
- Cancellation token support for asynchronous operations.
HttpRequestMessage
public class HttpRequestMessage : IDisposableRepresents 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 : IDisposableRepresents 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 : IDisposableRepresents 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.
Common Implementations of HttpContent
StringContent
public class StringContent : HttpContentRepresents an HTTP request or response body as a string.
View Details »ByteArrayContent
public class ByteArrayContent : HttpContentRepresents an HTTP request or response body as a byte array.
View Details »Helper Classes and Enums
HttpMethod
public class HttpMethodRepresents an HTTP method (verb).
Provides static instances for common HTTP methods like GET, POST, PUT, DELETE, etc.
HttpStatusCode
public enum HttpStatusCodeSpecifies values that define status codes returned by an HTTP server.
Examples include OK (200), NotFound (404), InternalServerError (500).
HttpRequestException
public class HttpRequestException : ExceptionThe exception that is thrown when an error occurs during an asynchronous HTTP request.
View Details »HttpMessageHandler
public abstract class HttpMessageHandler : IDisposableAn abstract base class for handling HTTP messages. This is used internally by HttpClient and can be extended for custom behavior (e.g., logging, authentication).