When a viewer accesses a webpage, the browser of the viewer makes a request to the server where the page is located. When a Web page is received and displayed by the browser, the server on which the page resides returns a message header (server header) that contains the HTTP status code to respond to the browser's request.
HTTP status code in English is HTTP status code.
The following are the common HTTP status codes:
200-Successful request
301-Resources (Web pages, etc.) are permanently transferred to other URLs
404-The requested resource (Web page, etc.) does not exist
500-Internal Server error
The HTTP status code consists of three decimal digits, the first decimal number defines the type of the status code, and the latter two numbers do not have a function of classification. There are 5 types of HTTP status codes:
HTTP Status Code classification classification classification description
1** information, the server receives the request and requires the requestor to continue the operation
2** successful, operation is successfully received and processed
3** Redirect, requires further action to complete the request
4** Client error, request contains syntax error or cannot complete request
5** Server error, the server has an error while processing the request
Status Code status Code English name Chinese description
Continue continued. The client should continue its request
101 Switching Protocols Switch protocol. The server switches the protocol based on the client's request. You can only switch to a more advanced protocol, for example, a new version of the protocol that switches to HTTP
The request was successful. Typically used for Get and post requests
201 Created has been created. A new resource was successfully requested and created
202 Accepted has been accepted. The request has been accepted, but the completion is not processed
203 Non-authoritative Information Non-authorized information. The request was successful. But the meta information returned is not on the original server, but a copy
204 no content. The server processed successfully, but the content was not returned. Make sure the browser continues to display the current document without updating the page
205 Reset content. The server processing succeeds, and the user terminal (for example: browser) should reset the document view. The browser's form fields can be cleared by this return code
206 partial content. The server successfully processed a partial GET request
Multiple Choices multiple options. The requested resource can include multiple locations, which can return a list of resource characteristics and addresses for use in the user terminal (for example: browser) selection
301 Moved Permanently permanent movement. The requested resource has been permanently moved to the new URI, the return information will include the new URI, and the browser will automatically redirect to the new URI. Any future new requests should be replaced with a new URI
302 Found Temporary movement. Similar to 301. But resources are only temporarily moved. The client should continue to use the original URI
303 See other addresses. Similar to 301. Viewing with Get and post requests
304 Not Modified has not been modified. The requested resource is not modified and no resources are returned when the server returns this status code. Clients typically cache accessed resources by providing a header indicating that the client wants to return only the resources modified after the specified date
305 Use Proxy. The requested resource must be accessed through the proxy
306 Unused has been deprecated HTTP status code
307 temporary Redirect temporary redirection. Similar to 302. REDIRECT with GET request
Bad request syntax error for client, server does not understand
401 Unauthorized Request for user authentication
402 Payment Required reserved for future use
403 Forbidden Server understands request client requests, but refuses to execute this request
404 Not the Found server could not find resources (Web pages) based on client requests. With this code, the Web designer can set up a personalized page that "the resource you requested could not be found"
405 Method not allowed in client request is forbidden
406 Not acceptable server failed to complete request based on content characteristics requested by client
407 Proxy authentication Required request proxy authentication, similar to 401, but requester should use proxy for authorization
408 Request time-out server waits for too long to be sent by the client, time-out
409 The Conflict server completes a put request from the client, it is possible to return this code, and the server handles the request when a conflict occurs
The resource requested by the 410 Gone client is no longer present. 410 is different from 404, if the resource is now permanently deleted and can use 410 code, the site designer can specify a new location for the resource through 301 code
411 Length Required Server cannot process request information sent by client without content-length
412 Precondition Failed Client request information for prerequisites error
413 Request Entity Too Large The requested entity is too large to be processed by the server, and therefore rejects it. To prevent successive requests from the client, the server may close the connection. If only the server is temporarily unable to process, it will contain a retry-after response message
414 Request-uri Too Large The requested URI is too long (URI is usually URL), the server cannot process
415 Unsupported Media Type Server is unable to process the medium format that was included with the request
416 requested range not satisfiable client requested range is not valid
417 Expectation Failed Server failed to satisfy expect request header information
Internal Server error Server internal errors, unable to complete the request
501 Not implemented server does not support the requested feature and cannot complete the request
502 Bad gateway acts as a gateway or proxy server, receiving an invalid request from the remote server
503 Service Unavailable The server is temporarily unable to process client requests due to overloading or system maintenance. The length of the delay can be included in the server's Retry-after header information
504 Gateway time-out acts as a gateway or proxy server and does not get requests from the remote server in time
505 HTTP version not supported server does not support versions of the requested HTTP protocol and cannot complete processing
Content-type, content type, generally refers to the presence of Content-type in a Web page, which defines the type of network file and the encoding of the Web page, and determines in what form and in what encoding the browser will read the file. This is the reason why you often see the results of a click on an ASP page that is downloaded to a file or a picture.
The HTTP request header provides information about the request, response, or other sending entity.
In this section we will cover HTTP response header information specifically.
Answer Header Description
Allow
Which request methods are supported by the server (such as GET, post, etc.).
Content-encoding
The encoding (Encode) method of the document. The content type specified by the Content-type header can be obtained only after decoding. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java's gzipoutputstream can be easily gzip compressed, but only on Unix Netscape and IE 4, ie 5 on Windows. Therefore, the servlet should check whether the browser supports gzip by looking at the accept-encoding header (that is, Request.getheader ("accept-encoding")). Returns the gzip-compressed HTML page for a browser that supports gzip, returning a normal page for another browser.
Content-length
Represents the content length. This data is only required if the browser is using a persistent HTTP connection. If you want to take advantage of the persistent connection, you can write the output document to Bytearrayoutputstream, look at its size when done, then put that value into the Content-length header and finally pass the Bytearraystream.writeto ( Response.getoutputstream () Send content.
Content-type
Indicates what MIME type the following document belongs to. The servlet defaults to Text/plain, but it usually needs to be explicitly specified as text/html. Because Content-type is often set up, HttpServletResponse provides a dedicated method setContentType.
Date
The current GMT time. You can use Setdateheader to set this header to avoid the hassle of converting the time format.
Expires
When should I think that the document has expired so that it is no longer cached?
Last-modified
The last modification time of the document. The customer can provide a date through the If-modified-since request header, which is treated as a conditional get, and only documents that have been modified later than the specified time are returned, otherwise a 304 (not Modified) state is returned. Last-modified can also be set using the Setdateheader method.
Location
Indicates where the customer should go to extract the document. Location is usually not set directly, but by HttpServletResponse's Sendredirect method, which sets the status code to 302.
Refresh
Indicates how much time the browser should refresh the document, in seconds. In addition to refreshing the current document, you can also pass SetHeader ("Refresh", "5; Url=http://host/path ") lets the browser read the specified page.
Note This functionality is usually done by setting the HTML page in the head area of the <meta http-equiv= "Refresh" content= "5; Url=http://host/path "" is implemented because automatic refresh or redirection is important for HTML writers who cannot use CGI or servlets. For Servlets, however, it is more convenient to set the refresh header directly.
Note that the meaning of refresh is "refresh this page after n seconds or visit the specified page" instead of "refresh this page every n seconds or visit the specified page". Therefore, continuous refresh requires a refresh header to be sent each time, and sending a 204 status code prevents the browser from continuing to refresh, whether it is using the refresh header or the <meta http-equiv= "Refresh" ... >
Note that the refresh header is not part of the HTTP 1.1 formal specification, but rather an extension, but both Netscape and IE support it.
Server
Server name. The servlet generally does not set this value, but is set by the Web server itself.
Set-cookie
Sets the cookie associated with the page. The servlet should not use Response.setheader ("Set-cookie", ...), but should use the dedicated method Addcookie provided by HttpServletResponse. See below for a discussion of cookie settings.
Www-authenticate
What type of authorization information should the customer provide in the authorization header? This header is required in an answer that contains a 401 (unauthorized) status line. For example, Response.setheader ("Www-authenticate", "BASIC realm=\" Executives\ "").
Note that the servlet generally does not handle this, but instead gives the Web server a special mechanism to control access to password-protected pages (for example,. htaccess).
HTTP message Structure
HTTP is an architecture model based on client/server (c/s) that exchanges information through a reliable link and is a stateless request/response protocol.
An HTTP "client" is an application (Web browser or any other client) that connects to the server to achieve the purpose of sending one or more HTTP requests to the server.
An HTTP "server" is also an application (typically a Web service, such as an Apache Web server or an IIS server) that receives requests from clients and sends HTTP response data to the client.
HTTP uses a Uniform Resource identifier (Uniform Resource Identifiers, URI) to transfer data and establish a connection.
Once the connection is established, the data message is routed through the format [RFC5322] and Multipurpose Internet Mail Extensions (MIME) [RFC2045] that are used by similar Internet mail.
Client Request message
The client sends an HTTP request to the server with a request message that includes the following format: A request line, a request header (header), a blank line, and four parts of the request data, giving the general format of the request message.
Server Response Message
The HTTP response is also made up of four parts: the status line, the message header, the blank line, and the response body.
Introduction to HTTP
The HTTP protocol is an abbreviation for the Hyper Text Transfer Protocol (Hypertext Transfer Protocol), which is used to transfer hypertext to the local browser from the World Wide Web (www:world Wide Web) server.
HTTP is a TCP/IP communication protocol that transmits data (HTML files, image files, query results, and so on).
How HTTP Works
The HTTP protocol works on the client-server architecture. The browser sends all requests via URLs to the HTTP server, which is the Web servers, as an HTTP client.
The Web server has: Apache server, IIS server (Internet information Services) and so on.
The Web server sends a response message to the client, based on the received request.
The HTTP default port number is 80, but you can also change to 8080 or another port.
HTTP three-point considerations:
HTTP is no connection: the meaning of no connection is to limit the processing of only one request per connection. When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved.
HTTP is media Independent: This means that any type of data can be sent over HTTP as long as the client and the server know what to do with the data content. The client and server specify that the appropriate Mime-type content type be used.
HTTP is stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information.
Source: http://www.runoob.com/http/http-tutorial.html
HTTP status Code