Earlier this week, I was working on a specific project and encountered a specific error while working with some service calls over the wire. I ended up discussing with few people about whether or not I should return a specific StatusCode type for the situation I was dealing with. About 5 minutes after we started talking, I thought about how come I never blogged about the different status codes you may have. Something pretty “simple” and “frequent” if you code on the web.
Few minutes after that thought, I was on my desk, reading and writing again about those beautiful Http Status Codes numbers…
HttpStatusCode contains the values of status codes defined for HTTP.
This enumeration element is contained inside System.Net.
The System.Net namespace provides a simple programming interface for many of the protocols used on networks today.
The following picture is a screenshot of my Visual Studio 2012 UI while inspecting the HttpStatusCode enumeration.
For the matter of our project discussion, I ended up choosing the proper status code for the situation I was dealing with, but it was worth revisiting this concept.
- HttpStatusCode
The following is a detailed description of each status code.
Continue = 100
HttpStatusCode.Continue indicates that the client can continue with its request
SwitchingProtocols = 101
HttpStatusCode.SwitchingProtocols indicates that the protocol version or protocol is being changed
OK = 200
HttpStatusCode.OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive.
Created = 201
HttpStatusCode.Created indicates that the request resulted in a new resource created before the response was sent.
Accepted = 202
HttpStatusCode.Accepted indicates that the request has been accepted for further processing
NonAuthoritativeInformation = 203
HttpStatusCode.NonAuthoritativeInformation indicates that the returned metainformation is from a cached copy instead of the origin server and therefore may be incorrect.
NoContent = 204
HttpStatusCode.NoContent indicates that the request has been successfully processed and that the response is intentionally blank.
ResetContent = 205
HttpStatusCode.ResetContent indicates that the client should reset (not reload) the current resource.
PartialContent = 206
HttpStatusCode.PartialContent indicates that the response is a partial response as requested by a GET request that includes a byte range.
MultipleChoices = 300
HttpStatusCode.MultipleChoices indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response.
Ambiguous = 300
HttpStatusCode.Ambiguous indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response.
MovedPermanently = 301
HttpStatusCode.MovedPermanently indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response
Moved = 301
HttpStatusCode.Moved indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method.
Found = 302
HttpStatusCode.Found indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method.
Redirect = 302
HttpStatusCode.Redirect indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method.
SeeOther = 303
HttpStatusCode.SeeOther automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET.
RedirectMethod = 303
HttpStatusCode.RedirectMethod automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET.
NotModified = 304
HttpStatusCode.NotModified indicates that the client’s cached copy is up to date. The contents of the resource are not transferred.
UseProxy = 305
HttpStatusCode.UseProxy indicates that the request should use the proxy server at the URI specified in the Location header.
Unused = 306
HttpStatusCode.Unused is a proposed extension to the HTTP/1.1 specification that is not fully specified.
TemporaryRedirect = 307
HttpStatusCode.TemporaryRedirect indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method.
RedirectKeepVerb = 307
HttpStatusCode.RedirectKeepVerb indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method.
BadRequest = 400
HttpStatusCode.BadRequest indicates that the request could not be understood by the server. System.Net.HttpStatusCode.BadRequest is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code.
Unauthorized = 401
HttpStatusCode.Unauthorized indicates that the requested resource requires authentication. The WWW-Authenticate header contains the details of how to perform the authentication.
PaymentRequired = 402
HttpStatusCode.PaymentRequired is reserved for future use.
Forbidden = 403
HttpStatusCode.Forbidden indicates that the server refuses to fulfill the request.
NotFound = 404
HttpStatusCode.NotFound indicates that the requested resource does not exist on the server.
MethodNotAllowed = 405
HttpStatusCode.MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource.
NotAcceptable = 406
HttpStatusCode.NotAcceptable indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource.
ProxyAuthenticationRequired = 407
HttpStatusCode.ProxyAuthenticationRequired indicates that the requested proxy requires authentication. The Proxy-authenticate header contains the details of how to perform the authentication.
RequestTimeout = 408
HttpStatusCode.RequestTimeout indicates that the client did not send a request within the time the server was expecting the request.
Conflict = 409
HttpStatusCode.Conflict indicates that the request could not be carried out because of a conflict on the server.
Gone = 410
HttpStatusCode.Gone indicates that the requested resource is no longer available.
LengthRequired = 411
HttpStatusCode.LengthRequired indicates that the required Content-length header is missing.
PreconditionFailed = 412
HttpStatusCode.PreconditionFailed indicates that a condition set for this request failed, and the request cannot be carried out. Conditions are set with conditional request headers like If-Match, If-None-Match, or If-Unmodified-Since.
RequestEntityTooLarge = 413
HttpStatusCode.RequestEntityTooLarge indicates that the request is too large for the server to process.
RequestUriTooLong = 414
HttpStatusCode.RequestUriTooLong indicates that the URI is too long..
UnsupportedMediaType = 415
HttpStatusCode.UnsupportedMediaType indicates that the request is an unsupported type.
RequestedRangeNotSatisfiable = 416
HttpStatusCode.RequestedRangeNotSatisfiable indicates that the range of data requested from the resource cannot be returned, either because the beginning of the range is before the beginning of the resource, or the end of the range is after the end of the resource.
ExpectationFailed = 417
HttpStatusCode.ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server.
InternalServerError = 500
HttpStatusCode.InternalServerError indicates that a generic error has occurred on the server.
NotImplemented = 501
HttpStatusCode.NotImplemented indicates that the server does not support the requested function.
BadGateway = 502
HttpStatusCode.BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server.
ServiceUnavailable = 503
HttpStatusCode.ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance.
GatewayTimeout = 504
HttpStatusCode.GatewayTimeout indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server.
HttpVersionNotSupported = 505
HttpStatusCode.HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server
Check here for some online documentation about HttpStatusCode.