How HTTP works

Source: Internet
Author: User

Strong http://blog.csdn.net/microtong
Oak CMS Content Management System http://www.oakcms.cn http://www.oakcms.net

HTTP Workflow

The HTTP protocol defines how the Web Client Requests web pages from the Web server and how the server sends web pages to the client. The HTTP protocol uses the request/response model. The client sends a request message to the server. The request message contains the request method, URL, Protocol version, request header, and request data. The server responds with a status line. The response content includes the Protocol version, successful or error code, server information, response header, and response data. The following figure shows the request/response model.

 

 

The following are the steps for HTTP Request/response:

(1) connecting the client to the Web server

An HTTP client, usually a browser, establishes a TCP socket connection with the http port of the Web server (80 by default. For example, http://www.oakcms.cn.

(2) Send an HTTP request

Through a TCP socket, the client sends a text request packet to the Web server. A request packet consists of four parts: request line, request header, blank line, and request data.

(3) The Server accepts the request and returns an HTTP Response

The Web server parses the request and locates the request resource. The server writes a copy of the resource to a TCP socket, which is read by the client. A response consists of status lines, response headers, empty rows, and response data.

(4) release the TCP Connection

The Web server proactively closes TCP sockets and releases TCP connections. The client passively closes TCP sockets and releases TCP connections.

(5) parse HTML content in the client browser

The client browser first parses the status line to check the status code indicating whether the request is successful. Then, parse each response header and inform the response header of the following characters: HTML documents and character sets of documents. The client browser reads the response data HTML, formatted it according to the HTML syntax, and displayed in the browser window.

Stateless HTTP protocol

HTTP is stateless ). That is to say, when the same client accesses the page on the same server for the second time, the server cannot know that the client has accessed the page, and the server cannot identify different clients. The stateless feature of HTTP simplifies the design of the server, making it easier for the server to support a large number of concurrent HTTP requests.

Persistent connection

Http1.0 uses non-persistent connections. The client must establish and maintain a new connection for each object to be requested. Because the same page may have multiple objects, non-persistent connections may slow down the download of a page, and such short connections increase the network transmission burden. Http1.1 introduces a persistent connection that allows multiple data requests and responses in the same connection. In this case, the server does not close the TCP connection after sending a response, the client can continue to request other objects through this connection.

Strong http://blog.csdn.net/microtong
Oak CMS Content Management System http://www.oakcms.cn http://www.oakcms.net

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.