System.Net.Http Namespace

Provides classes for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. This namespace is fundamental for building web-connected applications in .NET, enabling scenarios like consuming RESTful APIs, web scraping, and interacting with web services.

Classes

public class HttpClient : IDisposable

Provides a base class for sending HTTP requests and receiving HTTP responses from a Uri.

Summary:

  • The primary class for performing HTTP operations.
  • Supports sending requests asynchronously.
  • Manages connections efficiently.

See Also:

public class HttpClientHandler : HttpMessageHandler

Provides a default implementation of the HttpMessageHandler class.

Summary:

  • Configures behavior for HTTP requests, such as proxies, cookies, and credentials.
  • Can be used to customize `HttpClient`'s request processing.
public class HttpRequestMessage : IDisposable

Represents an HTTP request message.

Summary:

  • Encapsulates all information needed to send an HTTP request.
  • Includes method (GET, POST, etc.), URI, headers, and content.
public class HttpResponseMessage : IDisposable

Represents a message that is sent to an HTTP server as part of a request.

Summary:

  • Represents an HTTP response received from a server.
  • Includes status code, headers, and response content.
public abstract class HttpContent : IDisposable

A base class representing HTTP content, such as an HTTP message body.

Summary:

  • Abstract base class for HTTP request and response content.
  • Provides methods for reading and writing content.
  • Concrete implementations include `StringContent`, `ByteArrayContent`, `StreamContent`, and `FormUrlEncodedContent`.
public class StringContent : HttpContent

Represents an HTTP String content.

Summary:

  • A concrete implementation of HttpContent for string data.
  • Allows specifying encoding and media type.
public class FormUrlEncodedContent : HttpContent

Represents form-urlencoded content.

Summary:

  • Used for submitting form data in `application/x-www-form-urlencoded` format.
  • Takes a collection of key-value pairs.

Structs

public enum HttpCompletionOption

Specifies when an operation completes.

Summary:

  • Defines values like ResponseContentRead and ResponseHeadersRead.
  • Controls when an asynchronous HTTP operation is considered complete.

Interfaces

public abstract class HttpMessageHandler : IDisposable

Provides an abstract base class for sending HTTP messages.

Summary:

  • Represents a mechanism for sending HTTP requests.
  • HttpClient uses instances of this class to send requests.