Table of contents
Open Table of contents
Introduction
HTTP status codes are standard response codes given by web servers on the internet. They are used to indicate the status of a request made by a client to the server. In this post, I will explain the most common HTTP status codes and their meanings.
Explanation of HTTP Status Codes
1xx Informational
- 100 Continue: The server has received the request headers and the client should proceed to send the request body.
- 101 Switching Protocols: The server is changing protocols, such as switching to a newer version of HTTP.
- 102 Processing: The server has received and is processing the request, but no response is available yet.
- 103 Early Hints: Used to return some response headers before the final response.
2xx Success
- 200 OK: The request was successful.
- 201 Created: The request has been fulfilled and a new resource has been created.
- 202 Accepted: The request has been accepted for processing, but the processing has not been completed.
- 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK from its origin but is returning a modified version.
- 204 No Content: The server successfully processed the request but is not returning any content.
- 205 Reset Content: The server successfully processed the request but is not returning any content, and the client should reset the document view.
- 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.
- 207 Multi-Status: The message body that follows is an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.
- 208 Already Reported: The members of a DAV binding have already been enumerated in a previous reply to this request, and are not being included again.
- 226 IM Used: The server has fulfilled a GET request for the resource and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
3xx Redirection
- 300 Multiple Choices: The request has more than one possible response. The user-agent or the user should choose one of them.
- 301 Moved Permanently: The URL of the requested resource has been changed permanently. The new URL should be given in the response.
- 302 Found: This response code means that the URI of the requested resource has been changed temporarily.
- 303 See Other: The server sent this response to direct the client to get the requested resource at another URI with a GET request.
- 304 Not Modified: This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.
- 307 Temporary Redirect: The server sends this response to direct the client to get the requested resource at another URI with the same method that was used in the prior request.
- 308 Permanent Redirect: This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: If a POST was used in the first request, a POST must be used in the second request.
4xx Client Errors
- 400 Bad Request: The server could not understand the request due to invalid syntax.
- 401 Unauthorized: Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”. That is, the client must authenticate itself to get the requested response.
- 403 Forbidden: The client does not have permission to access the requested resource.
- 404 Not Found: The server can not find the requested resource. In the browser, this means the URL is not recognized.
- 405 Method Not Allowed: The method specified in the request is not allowed.
- 406 Not Acceptable: The server can only generate a response that is not accepted by the client.
- 407 Proxy Authentication Required: This response is similar to 401 but authentication is needed to be done by a proxy.
- 408 Request Timeout: This response is sent on an idle connection by some servers, even without any previous request by the client.
- 409 Conflict: This response would be sent when a request conflict with the current state of the server.
- 410 Gone: This response would be sent when the requested content has been permanently deleted from the server, with no forwarding address.
- 411 Length Required: Server rejected the request because the Content-Length header field is not defined and the server requires it.
- 412 Precondition Failed: The client has indicated preconditions in its headers which the server does not meet.
- 413 Payload Too Large: Request entity is larger than limits defined by the server; the server might close the connection or return a
Retry-After
header field. - 414 URI Too Long: The URI requested by the client is longer than the server is willing to interpret.
- 415 Unsupported Media Type: The media format of the requested data is not supported by the server, so the server is rejecting the request.
- 416 Range Not Satisfiable: The range specified by the Range header field in the request can’t be fulfilled; it’s possible that the range is outside the size of the target URI’s data.
- 417 Expectation Failed: This response code means the expectation indicated by the Expect request header field can’t be met by the server.
- 418 I’m a teapot: The server refuses the attempt to brew coffee with a teapot.
- 421 Misdirected Request: The request was directed at a server that is not able to produce a response.
- 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.
- 423 Locked: The resource that is being accessed is locked.
- 424 Failed Dependency: The request failed due to failure of a previous request.
- 425 Too Early: Indicates that the server is unwilling to risk processing a request that might be replayed.
- 426 Upgrade Required: The client should switch to a different protocol such as TLS/1.0.
- 428 Precondition Required: The origin server requires the request to be conditional.
- 429 Too Many Requests: The user has sent too many requests in a given amount of time.
- 431 Request Header Fields Too Large: The server is unwilling to process the request because either an individual header field or all the header fields collectively are too large.
- 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.
5xx Server Errors
- 500 Internal Server Error: The server has encountered a situation it doesn’t know how to handle.
- 501 Not Implemented: The request method is not supported by the server and cannot be handled.
- 502 Bad Gateway: This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.
- 503 Service Unavailable: The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded.
- 504 Gateway Timeout: This error response is given when the server is acting as a gateway and cannot get a response in time.
- 505 HTTP Version Not Supported: The HTTP version used in the request is not supported by the server.
- 506 Variant Also Negotiates: The server has an internal configuration error: transparent content negotiation for the request results in a circular reference.
- 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.
- 508 Loop Detected: The server detected an infinite loop while processing the request.
- 510 Not Extended: Further extensions to the request are required for the server to fulfill it.
- 511 Network Authentication Required: The 511 status code indicates that the client needs to authenticate to gain network access.
Code
The following code snippets are the frequently used in my projects.
PHP
<?php
public static $HTTP_CONTINUE = ['code' => 100, 'message' => 'Continue'];
public static $HTTP_SWITCHING_PROTOCOLS = ['code' => 101, 'message' => 'Switching Protocols'];
public static $HTTP_PROCESSING = ['code' => 102, 'message' => 'Processing'];
public static $HTTP_EARLY_HINTS = ['code' => 103, 'message' => 'Early Hints'];
public static $HTTP_OK = ['code' => 200, 'message' => 'OK'];
public static $HTTP_CREATED = ['code' => 201, 'message' => 'Created'];
public static $HTTP_ACCEPTED = ['code' => 202, 'message' => 'Accepted'];
public static $HTTP_NON_AUTHORITATIVE_INFORMATION = ['code' => 203, 'message' => 'Non-Authoritative Information'];
public static $HTTP_NO_CONTENT = ['code' => 204, 'message' => 'No Content'];
public static $HTTP_RESET_CONTENT = ['code' => 205, 'message' => 'Reset Content'];
public static $HTTP_PARTIAL_CONTENT = ['code' => 206, 'message' => 'Partial Content'];
public static $HTTP_MULTI_STATUS = ['code' => 207, 'message' => 'Multi-Status'];
public static $HTTP_ALREADY_REPORTED = ['code' => 208, 'message' => 'Already Reported'];
public static $HTTP_IM_USED = ['code' => 226, 'message' => 'IM Used'];
public static $HTTP_MULTIPLE_CHOICES = ['code' => 300, 'message' => 'Multiple Choices'];
public static $HTTP_MOVED_PERMANENTLY = ['code' => 301, 'message' => 'Moved Permanently'];
public static $HTTP_FOUND = ['code' => 302, 'message' => 'Found'];
public static $HTTP_SEE_OTHER = ['code' => 303, 'message' => 'See Other'];
public static $HTTP_NOT_MODIFIED = ['code' => 304, 'message' => 'Not Modified'];
public static $HTTP_TEMPORARY_REDIRECT = ['code' => 307, 'message' => 'Temporary Redirect'];
public static $HTTP_PERMANENT_REDIRECT = ['code' => 308, 'message' => 'Permanent Redirect'];
public static $HTTP_BAD_REQUEST = ['code' => 400, 'message' => 'Bad Request'];
public static $HTTP_UNAUTHORIZED = ['code' => 401, 'message' => 'Unauthorized'];
public static $HTTP_FORBIDDEN = ['code' => 403, 'message' => 'Forbidden'];
public static $HTTP_NOT_FOUND = ['code' => 404, 'message' => 'Not Found'];
public static $HTTP_METHOD_NOT_ALLOWED = ['code' => 405, 'message' => 'Method Not Allowed'];
public static $HTTP_NOT_ACCEPTABLE = ['code' => 406, 'message' => 'Not Acceptable'];
public static $HTTP_PROXY_AUTHENTICATION_REQUIRED = ['code' => 407, 'message' => 'Proxy Authentication Required'];
public static $HTTP_REQUEST_TIMEOUT = ['code' => 408, 'message' => 'Request Timeout'];
public static $HTTP_CONFLICT = ['code' => 409, 'message' => 'Conflict'];
public static $HTTP_GONE = ['code' => 410, 'message' => 'Gone'];
public static $HTTP_LENGTH_REQUIRED = ['code' => 411, 'message' => 'Length Required'];
public static $HTTP_PRECONDITION_FAILED = ['code' => 412, 'message' => 'Precondition Failed'];
public static $HTTP_PAYLOAD_TOO_LARGE = ['code' => 413, 'message' => 'Payload Too Large'];
public static $HTTP_URI_TOO_LONG = ['code' => 414, 'message' => 'URI Too Long'];
public static $HTTP_UNSUPPORTED_MEDIA_TYPE = ['code' => 415, 'message' => 'Unsupported Media Type'];
public static $HTTP_RANGE_NOT_SATISFIABLE = ['code' => 416, 'message' => 'Range Not Satisfiable'];
public static $HTTP_EXPECTATION_FAILED = ['code' => 417, 'message' => 'Expectation Failed'];
public static $HTTP_IM_A_TEAPOT = ['code' => 418, 'message' => "I'm a teapot"];
public static $HTTP_MISDIRECTED_REQUEST = ['code' => 421, 'message' => 'Misdirected Request'];
public static $HTTP_UNPROCESSABLE_ENTITY = ['code' => 422, 'message' => 'Unprocessable Entity'];
public static $HTTP_LOCKED = ['code' => 423, 'message' => 'Locked'];
public static $HTTP_FAILED_DEPENDENCY = ['code' => 424, 'message' => 'Failed Dependency'];
public static $HTTP_TOO_EARLY = ['code' => 425, 'message' => 'Too Early'];
public static $HTTP_UPGRADE_REQUIRED = ['code' => 426, 'message' => 'Upgrade Required'];
public static $HTTP_PRECONDITION_REQUIRED = ['code' => 428, 'message' => 'Precondition Required'];
public static $HTTP_TOO_MANY_REQUESTS = ['code' => 429, 'message' => 'Too Many Requests'];
public static $HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = ['code' => 431, 'message' => 'Request Header Fields Too Large'];
public static $HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = ['code' => 451, 'message' => 'Unavailable For Legal Reasons'];
public static $HTTP_INTERNAL_SERVER_ERROR = ['code' => 500, 'message' => 'Internal Server Error'];
public static $HTTP_NOT_IMPLEMENTED = ['code' => 501, 'message' => 'Not Implemented'];
public static $HTTP_BAD_GATEWAY = ['code' => 502, 'message' => 'Bad Gateway'];
public static $HTTP_SERVICE_UNAVAILABLE = ['code' => 503, 'message' => 'Service Unavailable'];
public static $HTTP_GATEWAY_TIMEOUT = ['code' => 504, 'message' => 'Gateway Timeout'];
public static $HTTP_HTTP_VERSION_NOT_SUPPORTED = ['code' => 505, 'message' => 'HTTP Version Not Supported'];
public static $HTTP_VARIANT_ALSO_NEGOTIATES = ['code' => 506, 'message' => 'Variant Also Negotiates'];
public static $HTTP_INSUFFICIENT_STORAGE = ['code' => 507, 'message' => 'Insufficient Storage'];
public static $HTTP_LOOP_DETECTED = ['code' => 508, 'message' => 'Loop Detected'];
public static $HTTP_NOT_EXTENDED = ['code' => 510, 'message' => 'Not Extended'];
public static $HTTP_NETWORK_AUTHENTICATION_REQUIRED = ['code' => 511, 'message' => 'Network Authentication Required'];
Golang
const (
HTTP_CONTINUE = 100
HTTP_SWITCHING_PROTOCOLS = 101
HTTP_PROCESSING = 102
HTTP_EARLY_HINTS = 103
HTTP_OK = 200
HTTP_CREATED = 201
HTTP_ACCEPTED = 202
HTTP_NON_AUTHORITATIVE_INFORMATION = 203
HTTP_NO_CONTENT = 204
HTTP_RESET_CONTENT = 205
HTTP_PARTIAL_CONTENT = 206
HTTP_MULTI_STATUS = 207
HTTP_ALREADY_REPORTED = 208
HTTP_IM_USED = 226
HTTP_MULTIPLE_CHOICES = 300
HTTP_MOVED_PERMANENTLY = 301
HTTP_FOUND = 302
HTTP_SEE_OTHER = 303
HTTP_NOT_MODIFIED = 304
HTTP_TEMPORARY_REDIRECT = 307
HTTP_PERMANENT_REDIRECT = 308
HTTP_BAD_REQUEST = 400
HTTP_UNAUTHORIZED = 401
HTTP_FORBIDDEN = 403
HTTP_NOT_FOUND = 404
HTTP_METHOD_NOT_ALLOWED = 405
HTTP_NOT_ACCEPTABLE = 406
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407
HTTP_REQUEST_TIMEOUT = 408
HTTP_CONFLICT = 409
HTTP_GONE = 410
HTTP_LENGTH_REQUIRED = 411
HTTP_PRECONDITION_FAILED = 412
HTTP_PAYLOAD_TOO_LARGE = 413
HTTP_URI_TOO_LONG = 414
HTTP_UNSUPPORTED_MEDIA_TYPE = 415
HTTP_RANGE_NOT_SATISFIABLE = 416
HTTP_EXPECTATION_FAILED = 417
HTTP_IM_A_TEAPOT = 418
HTTP_MISDIRECTED_REQUEST = 421
HTTP_UNPROCESSABLE_ENTITY = 422
HTTP_LOCKED = 423
HTTP_FAILED_DEPENDENCY = 424
HTTP_TOO_EARLY = 425
HTTP_UPGRADE_REQUIRED = 426
HTTP_PRECONDITION_REQUIRED = 428
HTTP_TOO_MANY_REQUESTS = 429
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451
HTTP_INTERNAL_SERVER_ERROR = 500
HTTP_NOT_IMPLEMENTED = 501
HTTP_BAD_GATEWAY = 502
HTTP_SERVICE_UNAVAILABLE = 503
HTTP_GATEWAY_TIMEOUT = 504
HTTP_HTTP_VERSION_NOT_SUPPORTED = 505
HTTP_VARIANT_ALSO_NEGOTIATES = 506
HTTP_INSUFFICIENT_STORAGE = 507
HTTP_LOOP_DETECTED = 508
HTTP_NOT_EXTENDED = 510
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511
)