A complete HTTP request process

jxba 2020-11-12 22:23:54
complete http request process


 

HTTP The complete process of the request

1.1 The browser resolves according to the domain name IP Address

       The browser finds the corresponding domain name IP Address .DNS The search process is as follows :

  1. Browser cache : First search the browser's own DNS cache ( The cache time is shorter , Perhaps only 1 minute , And can only hold 1000 Cache ), Check whether there is an entry corresponding to the domain name in the cache and it has not expired , If so, this is the end of parsing , If not, proceed to 2 Step .
  2. System cache : The browser searches the operating system itself DNS cache , If found and not expired, stop searching , This is the end of parsing , If not, proceed to 3 Step .
  3. Router cache : Send a query request to the router , If so, this is the end of parsing , If not, proceed to 4 Step ..
  4. ISPDNS cache : Inquire about ISP( Internet service provider )  cache DNS Server for .

 

1.2 Browser and WEB The server creates a TCP Connect

       TCP Of 3 The second handshake .

 

1.3 The browser gives WEB Server sends a HTTP request

       One HTTP The request message is sent by the request line (request line)、 Request header (headers)、 Blank line (blank line) And request data (request body)4 Component composition .

1.3.1 Request line

       The request line is divided into three parts : Request method 、 Request address url and http Protocol version , They are separated by spaces . for example ,GET /index.html HTTP/1.1.

1. Request method

       HTTP/1.1 The defined request methods are 9 Kind of ( The following table ), The two most common get and post.( Reference resources :https://www.runoob.com/http/http-methods.html)

Serial number Method describe
1 GET Request the specified page information , And return the entity body .
2 HEAD Be similar to GET request , But there is no specific content in the response returned , For getting headers
3 POST Submit data to the specified resource for processing request ( For example, submit a form or upload a file ). Data is contained in the request body .POST Requests may lead to the creation of new resources and / Or modification of existing resources .
4 PUT The data transmitted from the client to the server replaces the content of the specified document .
5 DELETE Request the server to delete the specified page .
6 CONNECT HTTP/1.1 The protocol is reserved for the proxy server that can change the connection to pipeline mode .
7 OPTIONS Allow clients to view the performance of the server .
8 TRACE Echo requests received by server , Mainly used for testing or diagnosis .
9 PATCH It's right PUT Method supplement , Used to locally update known resources .

(1)GET

       When the client wants to read the document from the server , When you click the link on the web page or enter the web address in the address bar of the browser to browse the web page , All of them are GET The way .

    • GET Method requires the server to url Positioning of the Resources are placed in the data part of the response message , It will be sent to the client .
    • GET Use a question mark ‘?’ representative URL The end of and the beginning of the request parameters , Use... Between the parameters ‘&’ Symbols separate . for example /index.jsp?id=100&op=bind, obviously get Not suitable for transmitting private data .
    • Because different browsers have different character restrictions on the address , Half can only identify 1024 Characters , So if you need to transmit a lot of data , It's not suitable for GET The way . If the data is in English letters / Numbers , The same to send ; If it's a space , Convert to +; If it's in Chinese / Other characters , You just use the string BASE64 encryption , obtain :%E4%BD%A0%E5%A5%BD, among %XX Medium XX Is the symbol of 16 In base notation ASCII.

(2)POST

       Allow the client to provide more information to the server .POST Method encapsulates the request parameters in HTTP Request data , By name / The form of value appears , It can transmit a lot of data , such POST There is no limit to the size of the data transmitted , And it won't show up in URL in .POST Method request line does not contain data string , These data are stored in “ Request content ” part , Data is also used between data ‘&’ Symbols separate .POST Most of the methods are used in the form of the page . because POST Also can be done GET The function of , As a result, most people use POST The way , This is a myth .GET The way has its own characteristics and advantages , We should choose to use... According to different situations GET Or use POST. 

2.URL

       URL: Uniform resource locator , It is an abstract and unique identification method of resource location .

       form :< agreement >://< host >:< port >/< route >

       Ports and paths can sometimes be omitted (HTTP The default port number is 80)

 

3. Protocol version

       The format of the protocol version is :HTTP/ The major version number . Sub version number , Commonly used HTTP/1.0 and HTTP/1.1

1.3.2 Request header

       The request header adds some additional information to the request message , from “ name / value ” The composition of , Each row of a pair of , Use colons to separate names and values .

       There will be a blank line at the end of the request header , Indicates the end of the request header , Next is the request data .

 

1.3.3 Request data

       Request data not available GET Method used in , And in the POST Method used in .POST The method is suitable for situations where a customer is required to fill out a form . The longest used request header associated with the request data is Cntent-Type and Content-Length. Here's a POST Method :

POST /index.php HTTP/1.1 Request line : Request method Request address url http Protocol version
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Request header
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost/
Content-Length:25
Content-Type:application/x-www-form-urlencoded
Blank line
username=aa&password=1234 Request data 

1.4 Server response HTTP request , The browser gets HTML Code

       HTTP The response message consists of the status line (status line)、 Corresponding head (headers)、 Blank line (blank line) And response data (response body)4 Component composition .

 

1.4.1 Status line

       State line by 3 Part of it is made up of , Respectively : Protocol version 、 Status code 、 Status code scan . The protocol version is consistent with the request message , State code description is a simple description of state code .

classification Classification description
1** Information , The server receives the request , Requester is required to continue
2** success , Operation received and processed successfully
3** Redirect , Further action is required to complete the request
4** Client error , The request contains a syntax error or could not be completed
5** Server error , The server encountered an error while processing the request

Reference resources :https://www.runoob.com/http/http-status-codes.html

1.4.2 Response head

 

1.4.3 The response data

       It is used to store the data information that needs to be returned to the client .

HTTP/1.1 200 OK Status line
Date: Sun, 17 Mar 2013 08:12:54 GMT Response head
Server: Apache/2.2.8 (Win32) PHP/5.2.5
X-Powered-By: PHP/5.2.5
Set-Cookie: PHPSESSID=c0huq7pdkmm5gg6osoe3mgjmm3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 4393
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Blank line
<html> The response data
<head>
<title>HTTP Response example <title>
</head>
<body>
Hello HTTP!
</body>
</html>

1.5 Browser parsing HTML Code , And ask for HTML Resources in the code

       The browser gets HTML After the document , Start parsing HTML Code , When a static resource is encountered , Just ask the server to download .

1.6 close TCP Connect , The browser renders the page to the user

       The browser uses its own internal working mechanism , Put the requested static resource and HTML Code rendering , Present to the user .

 

 

Reference resources

https://blog.csdn.net/ailunlee/article/details/90600174

https://blog.csdn.net/yezitoo/article/details/78193794

 

版权声明
本文为[jxba]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple