The entire process of the HTTP request

Source: Internet
Author: User

The steps required to first understand the complete HTTP request-to-response process

1. 域名解析 2. 发起TCP的3次握手 3. 建立TCP连接后发起http请求 4. 服务器端响应http请求,浏览器得到html代码 5. 浏览器解析html代码,并请求html代码中的资源 6. 浏览器对页面进行渲染呈现给用户
1. Domain Name resolution
就是将网站名称转变成IP地址:localhost-->127.0.0.1像什么hosts文件,DNS域名解析等等可以实现这种功能
2.3-time handshake to initiate TCP
在客户机和服务器之间建立正常的TCP网络连接时:客户机首先发出一个SYN消息,服务器使用SYN+ACK应答表示接收到了这个消息,最后客户机再以ACK消息响应。这样在客户机和服务器之间才能建立起可靠的TCP连接,数据才可以在客户机和服务器之间传递。

What is the process of a complete HTTP transaction?

拿到域名对应的IP地址之后,User-Agent(一般是指浏览器)会以一个随机端口(1024 < 端口 < 65535)向服务器的WEB程序(常用的有httpd,nginx等)80端口发起TCP的连接请求。这个连接请求(原始的http请求经过TCP/IP4层模型的层层封包)到达服务器端后(这中间通过各种路由设备,局域网内除外),进入到网卡,然后是进入到内核的TCP/IP协议栈(用于识别该连接请求,解封包,一层一层的剥开),还有可能要经过Netfilter防火墙(属于内核的模块)的过滤,最终到达WEB程序(本文就以Nginx为例),最终建立了TCP/IP的连接。
3. Initiating HTTP requests (HTTP request)

The so-called HTTP request, which is the Web client sending information to the Web server, consists of three parts:

(1) Request line

例如:GET www.cnblogs.com HTTP/1.1请求行写法是固定的,由三部分组成,第一部分是请求方法:除了常见的只有Get和Post方法,实际上HTTP请求方法还有很多,比如: PUT方法,DELETE方法,HEAD方法,CONNECT方法,TRACE方法第二部分是请求网址,第三部分是HTTP版本。

(2) HTTP header

HTTP头在HTTP请求可以是3种HTTP头:1. 请求头(request header)  2. 普通头(general header)  3. 实体头(entity header)通常来说,由于Get请求往往不包含内容实体,因此也不会有实体头。

(3) Content

只在POST请求中存在,因为GET请求并不包含任何实体
4. Server-Side HTTP response (HTTP Response) request

When the Web server receives an HTTP request, it does some processing based on the requested information (the processing may be simply a static return page, or it will be returned after processing by a language such as ASP. NET, PHP, JSP, etc.), returning an HTTP response accordingly. HTTP responses are structurally similar to HTTP requests and are made up of three parts, namely:

1. Status line

例如:HTTP/1.1 200 OK第一部分是HTTP版本第二部分是响应状态码第三部分是状态码的描述    信息类 (100-199)    响应成功 (200-299)    重定向类 (300-399)    客户端错误类 (400-499)    服务端错误类 (500-599)

Detailed HTTP status messages see: HTTP status messages

2.HTTP Head

HTTP响应中包含的头包括:1. 响应头(response header) 2. 普通头(general header) 3. 实体头(entity header)。

3. Return content

HTTP响应内容就是HTTP请求所请求的信息。这个信息可以是一个HTML,也可以是一个图片。响应的数据格式通过Content-Type字段来获得:Content-Type:image/png;或者我们熟悉的Content-Type:text/html

The following are the values of some common content-type fields.

    text/plain    text/html    text/css    image/jpeg    image/png    image/svg+xml    audio/mp4    video/mp4    application/javascript    application/pdf    application/zip    application/atom+xml    
5. The browser parses the HTML code and requests the resources in the HTML code

Understanding Persistent connections

Sometimes we get an HTML page, in the process of parsing the browser to HTML, if we find that the additional URL needs to get the content, it will launch the HTTP request again to get the server, such as style files, pictures. Many HTTP requests, relying on only one TCP connection, are sufficient, which is called persistent connections. It is also called an HTTP request complete.

Reference:

Discussion on 1.HTTP protocol

2. What is the process of a complete HTTP transaction?

Getting Started with the 3.HTTP protocol

Category: TCP/IP

The entire process of the HTTP request

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.