संपादित करें

इसके माध्यम से साझा किया गया


System.Net.Http Namespace

Provides a programming interface for modern HTTP applications.

Classes

ByteArrayContent

Provides HTTP content based on a byte array.

DelegatingHandler

A type for HTTP handlers that delegate the processing of HTTP response messages to another handler, called the inner handler.

FormUrlEncodedContent

A container for name/value tuples encoded using application/x-www-form-urlencoded MIME type.

HttpClient

Provides a class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

HttpClientFactoryExtensions

Extensions methods for IHttpClientFactory.

HttpClientHandler

The default message handler used by HttpClient in .NET Framework and .NET Core 2.0 and earlier.

HttpContent

A base class representing an HTTP entity body and content headers.

HttpDiagnosticsHttpRequestMessageExtensions

Extensions for telemetry utilities.

HttpIOException

The exception that is thrown when an error occurs while reading the response.

HttpMessageHandler

A base type for HTTP message handlers.

HttpMessageHandlerFactoryExtensions

Extensions methods for IHttpMessageHandlerFactory.

HttpMessageInvoker

A specialty class that allows applications to call the SendAsync(HttpRequestMessage, CancellationToken) method on an HTTP handler chain.

HttpMethod

A helper class for retrieving and comparing standard HTTP methods and for creating new HTTP methods.

HttpProtocolException

The exception thrown when an HTTP/2 or an HTTP/3 protocol error occurs.

HttpRequestException

A base class for exceptions thrown by the HttpClient and HttpMessageHandler classes.

HttpRequestMessage

Represents a HTTP request message.

HttpRequestOptions

Represents a collection of options for an HTTP request.

HttpResilienceHttpRequestMessageExtensions

The resilience extensions for HttpRequestMessage.

HttpResponseMessage

Represents a HTTP response message including the status code and data.

MessageProcessingHandler

A base type for handlers which only do some small processing of request and/or response messages.

MultipartContent

Provides a collection of HttpContent objects that get serialized using the multipart/* content type specification.

MultipartFormDataContent

Provides a container for content encoded using multipart/form-data MIME type.

ReadOnlyMemoryContent

Provides HTTP content based on a ReadOnlyMemory<T>.

RtcRequestFactory
SocketsHttpConnectionContext

Represents the context passed to the ConnectCallback for a SocketsHttpHandler instance. .

SocketsHttpHandler

Provides the default message handler used by HttpClient in .NET Core 2.1 and later.

SocketsHttpPlaintextStreamFilterContext

Represents the context passed to the PlaintextStreamFilter for a SocketsHttpHandler instance.

StreamContent

Provides HTTP content based on a stream.

StringContent

Provides HTTP content based on a string.

WebRequestHandler

Provides desktop-specific features not available to Windows Store apps or other environments.

WinHttpHandler

Handles messages based on the WinHTTP interface of Windows. This class is intended for use in server environments.

Structs

HttpRequestOptionsKey<TValue>

Represents a key in the options collection for an HTTP request.

Interfaces

IHttpClientFactory

A factory abstraction for a component that can create HttpClient instances with custom configuration for a given logical name.

IHttpMessageHandlerFactory

A factory abstraction for a component that can create HttpMessageHandler instances with custom configuration for a given logical name.

Enums

ClientCertificateOption

Specifies how client certificates are provided.

CookieUsePolicy

This enumeration allows control of HTTP cookies when communicating with the server.

HttpCompletionOption

Indicates if HttpClient operations should be considered completed either as soon as a response is available, or after reading the entire response message including the content.

HttpKeepAlivePingPolicy

Specifies when the HTTP/2 ping frame is sent on an idle connection.

HttpRequestError

Defines error categories representing the reason for HttpRequestException or HttpIOException.

HttpVersionPolicy

Specifies behaviors for selecting and negotiating the HTTP version for a request.

WindowsProxyUsePolicy

This enumeration provides available options for the proxy settings used by an HttpClient when running on Windows.

Delegates

HeaderEncodingSelector<TContext>

Represents a method that specifies the encoding to use when interpreting header values.

Remarks

The System.Net.Http namespace is designed to provide the following:

  1. HTTP client components that allow users to consume modern web services over HTTP.

  2. HTTP components that can be used by both clients and servers (HTTP headers and messages, for example). This provides a consistent programming model on both the client and the server side for modern web services over HTTP.

The System.Net.Http namespace and the related System.Net.Http.Headers namespace provide the following set of components:

  1. HttpClient - the primary class used to send and receive requests over HTTP.

  2. HttpRequestMessage and HttpResponseMessage - HTTP messages as defined in RFC 2616 by the IETF.

  3. HttpHeaders - HTTP headers as defined in RFC 2616 by the IETF.

  4. HttpClientHandler - HTTP handlers responsible for producing HTTP response messages.

There are various HTTP message handlers that can be used. These include the following.

  1. DelegatingHandler - A class used to plug a handler into a handler chain.

  2. HttpMessageHandler - A simple class to derive from that supports the most common requirements for most applications.

  3. HttpClientHandler - A class that operates at the bottom of the handler chain that actually handles the HTTP transport operations.

  4. WebRequestHandler - A specialty class that operates at the bottom of the handler chain class that handles HTTP transport operations with options that are specific to the System.Net.HttpWebRequest object.

The contents of an HTTP message corresponds to the entity body defined in RFC 2616.

A number of classes can be used for HTTP content. These include the following.

  1. ByteArrayContent - HTTP content based on a byte array.

  2. FormUrlEncodedContent - HTTP content of name/value tuples encoded using application/x-www-form-urlencoded MIME type.

  3. MultipartContent - HTTP content that gets serialized using the multipart/* content type specification.

  4. MultipartFormDataContent - HTTP content encoded using the multipart/form-data MIME type.

  5. StreamContent - HTTP content based on a stream.

  6. StringContent - HTTP content based on a string.

If an app using the System.Net.Http and System.Net.Http.Headers namespaces intends to download large amounts of data (50 megabytes or more), then the app should stream those downloads and not use the default buffering. If the default buffering is used the client memory usage will get very large, potentially resulting in substantially reduced performance.

Classes in the System.Net.Http and System.Net.Http.Headers namespaces can be used to develop Windows Store apps or desktop apps. When used in a Windows Store app, classes in the System.Net.Http and System.Net.Http.Headers namespaces are affected by network isolation feature, part of the application security model used by the Windows 8. The appropriate network capabilities must be enabled in the app manifest for a Windows Store app for the system to allow network access by a Windows store app. For more information, see the Network Isolation for Windows Store Apps.

See also