HTTP status code Overview

Source: Internet
Author: User
Tags unsupported
The complete HTTP 1.1 specification comes from RFC 2616, you can in http://www.talentdigger.cn/home/link.php? Url = d3d3LnJmYy1lZGl0b3Iub3JnLw % 3D % 3D online query. The HTTP 1.1 Status Code is marked as a new feature because many browsers only Support HTTP 1.0. You should only send the status code to clients that support HTTP 1.1. The Supported Protocol version can be checked by calling request. getRequestProtocol.

The remaining content of this section details the status code in HTTP 1.1. These status codes are classified into five categories:

100-199 is used to specify the actions corresponding to the client.
200-299 indicates that the request is successful.
300-399 is used for moved files and is often included in the positioning header to specify the new address information.
400-499 is used to indicate client errors.
500-599 is used to support server errors.

Constants in HttpServletResponse represent status codes associated with different standard messages. In servlet programs, you will use more of these constant identifiers to use status codes. For example, you generally use response. setStatus (response. SC _NO_CONTENT) instead of response. setStatus (204), because the latter is hard to understand and can easily cause errors. However, you should note that the server allows slight changes to the message, while the client only pays attention to the numeric value of the status code. Therefore, the server may only return HTTP/1.1 200 instead of HTTP/1.1 200 OK.

100 (Continue/Continue)
If the server receives a request with a header containing 100-continue, this indicates whether the client can send attachments in subsequent requests. In this case, the server uses 100 (SC _CONTINUE) to allow the client to continue or uses 417 (Expectation Failed) to tell the client not to agree to accept the attachment. This status code is newly added in HTTP 1.1.

101 (Switching Protocols/conversion protocol)
101 (SC _SWITCHING_PROTOCOLS) Status Code indicates that the server changes the header information to a different protocol. This is newly added in HTTP 1.1.

200 (OK/normal)
200 (SC _ OK) means everything is normal. It is generally used for GET and POST requests. This status code is the default value for servlet. If the setStatus method is not called, 200 is returned.

201 (Created/Created)
201 (SC _CREATED) indicates that the server has created a new document in the Request Response; its URL should be provided in the positioning header information.

202 (Accepted/accept)
202 (SC _ACCEPTED) tells the client that the request is being executed, but the process has not been completed.

203 (Non-Authoritative Information/unofficial Information)
Status Code 203 (SC _NON_AUTHORITATIVE_INFORMATION) indicates that the document is returned normally. However, some response header information may be incorrect because the document copy is being used. This is newly added in HTTP 1.1.

204 (No Content/No Content)
If no new document exists, 204 (SC _NO_CONTENT) ensures that the browser displays the previous document. This status code is very useful for users to reload a page periodically, and you can determine whether the previous page has been updated. For example, a servlet may perform the following operations:
Int pageVersion = Integer. parseInt (request. getParameter ("pageVersion "));
If (pageVersion >;= currentVersion ){
Response. setStatus (response. SC _NO_CONTENT );
} Else {
// Create regular page
}
However, this method works for pages that are automatically reloaded by refreshing the response header information or equivalent HTML tags, because it returns a 204 status code to be reloaded after it is stopped. However, JavaScript-based Automatic overloading still needs to work in this case. Read the details in section 7.2 (HTTP 1.1 Response Headers and Their Meaning/HTTP 1.1 Response header information and Their meanings.

205 (Reset Content/Reset Content)
Resetting content 205 (SC _RESET_CONTENT) means that although there are no new documents, the browser needs to reset the document display. This status code is used to force the browser to clear form fields. This is newly added in HTTP 1.1.

206 (Partial Content/Partial Content)
206 (SC _PARTIAL_CONTENT) is sent when the server completes a local request containing the Range header information. This is newly added in HTTP 1.1.

300 (Multiple Choices/Multiple Choices)
300 (SC _MULTIPLE_CHOICES) indicates that the requested document can be found in multiple places and listed in the returned document. If the server has a preferred setting, the preferences will be listed in the positioning response header information.

301 (Moved Permanently)
301 (SC _MOVED_PERMANENTLY) indicates that the requested document is somewhere else. The new URL of the document is provided in the locating response header. The browser automatically connects to the new URL.

302 (Found/Found)
Similar to 301, only the URL given in the positioning header information should be understood as a temporary exchange address rather than permanent. Note: In HTTP 1.0, messages are Moved Temporarily rather than found. Therefore, the constant in HttpServletResponse is SC _MOVED_TEMPORARILY, not SC _FOUND.

Note:
The constant representing status code 302 is SC _MOVED_TEMPORARILY instead of SC _FOUND.

Status Code 302 is very useful because the browser automatically connects to the new URL specified in the response header. This is very useful, and there is a dedicated method for this-sendRedirect. Using response. sendRedirect (url) has several advantages over calling response. setStatus (response. SC _MOVED_TEMPORARILY) and response. setHeader ("Location", url. First, the response. sendRedirect (url) method is obviously simple and easy. Second, the servlet automatically creates a page to save this connection for Browser display that cannot be automatically switched. Finally, in servlet 2.2 (in J2EE), sendRedirect can process relative paths and automatically convert them to absolute paths. However, you can only use the absolute path in version 2.1.

If you direct the user to another page of the site, you must use the encodeURL method in HttpServletResponse to send the URL. This prevents the continuous use of URL-based rewriting session tracking. URL rewriting is a way to track users who do not use cookies on your website. This is achieved by attaching the path information at the end of each URL, but the servlet session tracking API automatically pays attention to these details. Session tracking is discussed in chapter 9 and the habit of using encodeURL makes it much easier to add session tracking later.

Core Skills
If you direct the user to other pages of your site, use response. sendRedirect (response. the encodeURL (url) method preplanned session tracking (session tracking) is better than calling response. sendRedirect (url) is much better.

This status code can be exchanged with 301 sometimes. For example, if you mistakenly accessed the http://www.talentdigger.cn/home/link.php? Url = aG9zdC9 % 2 BdXNlcg % 3D % 3D (the path information is incomplete), some servers will return the 301 status code, and some will return the 302 status code. Technically, if the initial request is a GET browser, it is assumed that the browser is automatically redirected. For more details, see the status code 307.

303 (See Other/refer to Other information)
This status code is similar to 301 and 302, but if the initial request is POST, the new document (given in the positioning header information) retrieves the medicinal GET. This status code is newly added to HTTP 1.1.

304 (Not Modified/for correction)
When the client has a cached document and provides an If-Modified-Since Header, it can be pointed out that the client only needs to reload the document after the specified date, in this way, conditional requests can be made. 304 (SC _NOT_MODIFIED) indicates that the buffer version has been updated and the client should refresh the document. In addition, the server will return the request's document and Status Code 200. Generally, the servlet does not directly set this status code. They implement the getLastModified method and allow the default service method to process conditional requests based on the corrected date. The routine of this method is provided in section 2.8 (An Example Using Servlet Initialization and Page Modification Dates/An Example of Using servlet Initialization and Page correction date.

305 (Use Proxy/Use Proxy)
305 (SC _USE_PROXY) indicates that the requested document should be obtained by the proxy server in the header information. This status code is newly added to HTTP 1.1.

307 (Temporary Redirect/Temporary redirection)
The rule that the browser uses to process the 307 status is the same as that in the 302 status. The 307 status is added to HTTP 1.1 because many browsers still perform an incorrect redirection even if the original message is POST when they receive the 302 response. It is assumed that the browser will redirect the POST request only when the 303 response is received. The purpose of adding this new status code is clear: when the response is 303, the request is redirected according to the GET and POST requests; when the response is 307, the request is redirected according to the GET request instead of the POST request. Note: For some reason, there are no constants corresponding to this state in HttpServletResponse. This status code is newly added to HTTP 1.1.

Note:
There is no SC _TEMPORARY_REDIRECT constant in HttpServletResponse, so you can only display 307 status codes.

400 (Bad Request/error Request)
400 (SC _BAD_REQUEST) indicates a syntax error in the client request.

401 (Unauthorized/Unauthorized)
401 (SC _UNAUTHORIZED) indicates that the client accesses the password-protected page when there is no valid identity information in the Authorization header. This response must contain a WWW-Authenticate authorization information header. For example, in part 1 of this book, "Restricting Access to Web Pages./restrict Access to Web Pages ."

403 (Forbidden/Forbidden)
403 (SC _FORBIDDEN) means that the server rejects the requested resources unless authorized. This status is often caused by corrupted files or directory licenses on the server.

404 (Not Found/Not Found)
404 (SC _NOT_FOUND) status each network programmer may have encountered, and he told the client that the address he gave could not find any resources. It is the standard way to indicate "No accessed page. This status code is a common response and has a special method to implement it in the HttpServletResponse class: sendError ("message "). The advantage of using sendError over setStatus is that the server automatically generates an error page to display the error message. However, the Internet Explorer 5 browser ignores the error page you are using by default and displays its custom error prompt page, although Microsoft violates the HTTP specification. To disable this function, select Internet in the tool menu to go to the Advanced tab, confirm that the "show friendly HTTP Error message" option (in my browser, It is the reciprocal 8th option) is not selected. However, few users know this option, so this feature is hidden by IE5 so that users cannot see the information you returned to users. Other mainstream browsers and IE4 completely display the server-generated error prompt page. See the examples in Figure 6-3 and 6-4.

Core warning
By default, IE5 ignores the error prompt page generated by the server.

405 (Method Not Allowed/Method Not Allowed)
405 (SC _METHOD_NOT_ALLOWED) indicates that the request method (GET, POST, HEAD, PUT, DELETE, etc.) is not allowed for certain resources. This status code is newly added to HTTP 1.1.

406 (Not Acceptable/inaccessible)
406 (SC _NOT_ACCEPTABLE) indicates that the MIME type of the requested resource is different from the type specified in the Accept header in the client. See introduction to MIME types in Table 7.2 (HTTP 7.1 Response Headers and Their Meaning/HTTP 1.1 Response header information and Their meanings) in part 1 of this book. 406 is newly added to HTTP 1.1.

407 (Proxy Authentication Required/Proxy Server Authentication requirements)
407 (SC _PROXY_AUTHENTICATION_REQUIRED) is similar to 401, but this status is used for proxy servers. This status indicates that the client must pass the authentication of the proxy server. The Proxy server returns a Proxy-Authenticate response header to the client, which causes the client to reconnect with the header information containing the Proxy-Authorization request. This status code is newly added to HTTP 1.1.

408 (Request Timeout/Request Timeout)
408 (SC _REQUEST_TIMEOUT) indicates that the server waits for the client to send a request for too long. This status code is newly added to HTTP 1.1.

409 (Conflict/Conflict)
This status is usually used together with the PUT request, and the 409 (SC _CONFLICT) status is often used to try to upload files with incorrect versions. This status code is newly added to HTTP 1.1.

410 (Gone/does not exist)
410 (SC _GONE) tells the client that the requested document does not exist and there is no updated address. The 410 status is different from the 404,410 status when the guidance document has been removed, and 404 is used for inaccessible for unknown reasons. This status code is newly added to HTTP 1.1.

411 (Length Required/Data Length Required)
411 (SC _LENGTH_REQUIRED) indicates that the server cannot process the request (assuming a POST request with an attachment) unless the client sends the Content-Length header to indicate the size of the data sent to the server. This status is newly added to HTTP 1.1.

412 (Precondition Failed/Precondition error)
412 (SC _PRECONDITION_FAILED) status indicates that some of the prerequisites in the request header information are incorrect. This status is newly added to HTTP 1.1.

413 (Request Entity Too Large/Request Entity is Too Large)
413 (SC _REQUEST_ENTITY_TOO_LARGE) tells the client that the requested document is larger than what the server wants to process now. If the server determines that it can be processed for a period of time, it will contain a Retry-After response header. This status is newly added to HTTP 1.1.

414 (Request URI Too Long/Request URI is Too Long)
414 (SC _REQUEST_URI_TOO_LONG) is used when the URI is too long. The "URI" here refers to the host, domain name, and port number in the URL. For example, in URL -- http://www.y2k-disaster.com: 8080/we/look/silly/now/, URI indicates/we/look/silly/now /. This status is newly added to HTTP 1.1.

415 (Unsupported Media Type/Unsupported Media Format)
415 (SC _UNSUPPORTED_MEDIA_TYPE) means that the server does not know how to handle the format of the attachment contained in the request. This status is newly added to HTTP 1.1.

416 (Requested Range Not Satisfiable/the request Range cannot be met)
416 indicates that the client contains a request that the server cannot meet the Range header information. This status is newly added to HTTP 1.1. It is strange that there is no corresponding constant in the HTTP servletresponse of the servlet 2.1 API to represent this state.

Note:
In the servlet 2.1 specification, the class HttpServletResponse does not have a constant such as SC _REQUESTED_RANGE_NOT_SATISFIABLE, so you can only use 416 directly. This constant is included after servlet 2.2.

417 (Expectation Failed/expected failure)
If the server obtains the response CT request header with a 100-continue value, this means that the client is asking whether attachments can be sent in subsequent requests. In this case, the server also uses this status (417) to tell the Browser Server not to receive the attachment or to tell the client to continue sending the attachment in the 100 (SC _CONTINUE) status. This status is newly added to HTTP 1.1.

500 (Internal Server Error/Internal Server Error)
500 (SC _INTERNAL_SERVER_ERROR) is a common "server error" status. This status is often caused by CGI programs (hopefully not so !) This error is caused by a servlet that cannot run normally or the format of the returned header information is incorrect.

501 (Not Implemented/Not Implemented)
501 (SC _NOT_IMPLEMENTED) status indicates that the client server does not support the required functions in the request. For example, the client executes commands that are not supported by a server such as PUT.

502 (Bad Gateway/wrong Gateway)
502 (SC _BAD_GATEWAY) is used as a proxy or gateway server. This status indicates that the receiving server receives an error response from the remote server.

503 (Service Unavailable/Service Unavailable)
Status code 503 (SC _SERVICE_UNAVAILABLE) indicates that the server cannot respond due to maintenance or overload. For example, if some threads or database connection pools are not idle, the servlet will return this header. The server provides a Retry-After header to tell the client when to give it a try.

504 (Gateway Timeout/Gateway Timeout)
This status is also used to act as a proxy or gateway server; it indicates that the receiving server does not receive a timely response from the remote server. This status is newly added to HTTP 1.1.

505 (HTTP Version Not Supported/unsupported HTTP Version)
The 505 (SC _HTTP_VERSION_NOT_SUPPORTED) Status Code indicates that the server does not support specifying the HTTP version in the request. This status is newly added to HTTP 1.1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.