Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hypertext Transfer Protocol (or HTTP) is a protocol for requesting resources from a web server. The System.Net.Http.HttpClient class exposes the ability to send HTTP requests and receive HTTP responses from a resource identified by a URI. Many types of resources are available on the web, and HTTP defines a set of request methods for accessing these resources.
The request methods are differentiated via several factors, first by their verb but also by the following characteristics:
HTTP method | Is idempotent | Is cacheable | Is safe |
---|---|---|---|
GET |
✔️ Yes | ✔️ Yes | ✔️ Yes |
POST |
❌ No | ⚠️ †Rarely | ❌ No |
PUT |
✔️ Yes | ❌ No | ❌ No |
PATCH |
❌ No | ❌ No | ❌ No |
DELETE |
✔️ Yes | ❌ No | ❌ No |
HEAD |
✔️ Yes | ✔️ Yes | ✔️ Yes |
OPTIONS |
✔️ Yes | ❌ No | ✔️ Yes |
TRACE |
✔️ Yes | ❌ No | ✔️ Yes |
CONNECT |
❌ No | ❌ No | ❌ No |
†The
POST
method is only cacheable when the appropriateCache-Control
orExpires
response headers are present. This is very uncommon in practice.
.NET provides comprehensive support for the HTTP protocol, which accounts for most internet traffic, with the HttpClient. For more information, see Make HTTP requests with the HttpClient class. Applications receive HTTP protocol errors by catching an HttpRequestException. HTTP status codes are either reported in HttpResponseMessage with the HttpResponseMessage.StatusCode or in HttpRequestException with the HttpRequestException.StatusCode in case the called method doesn't return a response message. For more information about error handling, see HTTP error handling, and for more information about status codes, see RFC 9110, HTTP Semantics: Status Codes.
The informational status codes reflect an interim response. Most of the interim responses, for example HttpStatusCode.Continue, are handled internally with HttpClient and are never surfaced to the user.
HTTP status code | HttpStatusCode |
---|---|
100 |
HttpStatusCode.Continue |
101 |
HttpStatusCode.SwitchingProtocols |
102 |
HttpStatusCode.Processing |
103 |
HttpStatusCode.EarlyHints |
The successful status codes indicate that the client's request was successfully received, understood, and accepted.
HTTP status code | HttpStatusCode |
---|---|
200 |
HttpStatusCode.OK |
201 |
HttpStatusCode.Created |
202 |
HttpStatusCode.Accepted |
203 |
HttpStatusCode.NonAuthoritativeInformation |
204 |
HttpStatusCode.NoContent |
205 |
HttpStatusCode.ResetContent |
206 |
HttpStatusCode.PartialContent |
207 |
HttpStatusCode.MultiStatus |
208 |
HttpStatusCode.AlreadyReported |
226 |
HttpStatusCode.IMUsed |
Redirection status codes require the user agent to take action to fulfill the request. Automatic redirection is turned on by default, it can be changed with HttpClientHandler.AllowAutoRedirect or SocketsHttpHandler.AllowAutoRedirect.
HTTP status code | HttpStatusCode |
---|---|
300 |
HttpStatusCode.MultipleChoices or HttpStatusCode.Ambiguous |
301 |
HttpStatusCode.MovedPermanently or HttpStatusCode.Moved |
302 |
HttpStatusCode.Found or HttpStatusCode.Redirect |
303 |
HttpStatusCode.SeeOther or HttpStatusCode.RedirectMethod |
304 |
HttpStatusCode.NotModified |
305 |
HttpStatusCode.UseProxy |
306 |
HttpStatusCode.Unused |
307 |
HttpStatusCode.TemporaryRedirect or HttpStatusCode.RedirectKeepVerb |
308 |
HttpStatusCode.PermanentRedirect |
The client error status codes indicate that the client's request was invalid.
The server error status codes indicate that the server encountered an unexpected condition that prevented it from fulfilling the request.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Implement HTTP operations in ASP.NET Core Blazor Web apps - Training
Implement HTTP operations in ASP.NET Core Blazor Web apps