Basics of how HTTP Works

Source: Internet
Author: User

After the client establishes a connection with the server, it sends a request to the server in the format: Uniform Resource Identifier, protocol version number. The server receives the requested information (including the request line, the request header, the request body). After the server receives the request, it gives the corresponding response information in the form of a status line (including response line, response header, response body).

On the Internet, HTTP traffic typically occurs on top of a TCP/IP connection. The default port is port 80 of TCP.

The information exchange process of the client/server model based on the HTTP protocol is divided into four processes: establishing a connection, sending a request message, sending a response message, and closing a connection.

The server may accept multiple requests at the same time, resulting in multiple sessoin, each of which processes its own request.


The working process of HTTP
An HTTP operation is called a transaction, and the whole process is as follows:
1), Address resolution
If you request this page using a client browser: http://localhost.com:8080/index.htm

From the decomposition of the protocol name, host name, port, object path, and so on, for our address, the result of the resolution are as follows:
Protocol Name: HTTP
Host Name: localhost.com
Port: 8080
Object path:/index.html

In this step, domain Name System DNS is required to resolve the domain name localhost.com, the IP address of the host.


2), encapsulating HTTP request Packets
The above part is combined with the information of the machine itself, encapsulated into an HTTP request packet


3) encapsulated into TCP packet, establish TCP connection (three handshake of TCP)
Before HTTP work begins, the client (Web browser) first connects to the server over the network, which is done through TCP, which works with the IP protocol to build the Internet, known as the TCP/IP protocol family, so the internet is also known as tcp/ IP network. HTTP is a higher level of application-level protocol than TCP, according to the rules, only the lower layer protocol is established before the protocol can be more connected, so the first to establish a TCP connection, the port number of the general TCP connection is 80. This is port 8080.


4) client sends request command
After the connection is established, the client sends a request to the server in the form of a Uniform Resource Identifier (URL), a protocol version number, followed by MIME information including the request modifier, client information, and content.

5) Server Response
After the server receives the request, it gives the corresponding response information in the form of a status line, including the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content.
The entity message is that after the server sends the header information to the browser, it sends a blank line to indicate that the header information is sent to this end, and then it sends the actual data requested by the user in the format described in the Content-type reply header information


6) The server shuts down the TCP connection
In general, once the Web server sends the request data to the browser, it closes the TCP connection and then if the browser or server joins this line of code in its header information
Connection:keep-alive
The TCP connection remains open after it is sent, so the browser can continue to send requests through the same connection. Maintaining a connection saves the time it takes to establish a new connection for each request and also saves network bandwidth.



The server passes the response information to the client, and the content in the response body may be an HTML page or a picture that is read out through the input stream and written back to the monitor.

Basics of how HTTP Works

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.