HTTP hypertext Protocol, make HTTP no longer difficult to understand

Source: Internet
Author: User
Tags html page requires
HTTP Hypertext Protocol, make HTTP no longer difficult to understand

Let's start with a map and then break it down:

Guide Map Details:

Agreement

Hypertext Transfer Protocol, Hypertext Transfer Protocol

A stateless request/response protocol

Is the most widely used network transmission protocol on the Internet, all www files must abide by this standard

Transmission of data (HTML files, image files, query results, etc.) based on TCP/IP communication protocol

Working principle

Working on client-server architecture as top

The Web server sends a response message to the client based on the received request

The browser sends all requests through the URL to the HTTP server as the HTTP client.

Precautions

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.

HTTP response

Client Request message

Diagram

Part

Request Line

Request Header (header)

Blank Line

Request data

Server Response Message

Diagram

Part

Status line

Message header

Blank Line

Response body

Request method

GET

Requests the specified page information and returns the entity principal.

HEAD

Similar to a GET request, except that there is no specific content in the returned response to get the header

POST

Submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources.

PUT

Supersedes the contents of the specified document from the data that the client sends to the server.

DELETE

Requests that the server delete the specified page.

CONNECT

The http/1.1 protocol is reserved for proxy servers that can change connections to pipelines.

OPTIONS

Allows clients to view server performance.

TRACE

echo the requests received by the server, primarily for testing or diagnostics.

Response header Information

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 Bytearrayoutputstram, 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 you should 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 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).

Status code

Description

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.

Classification

1**-Information, the server receives the request and requires the requestor to continue to perform the operation

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.