HTTP status code

Source: Internet
Author: User
Tags unsupported

The complete HTTP 1.1 specification is from RFC 2616. You can view it at http://www.rfc-editor.org/on-line. 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 ServletProgram, 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 access http: // host /~ If 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.