Skip to content

计算机网络

互联网协议(五层模型)

  1. 应用层
  2. 传输层
  3. 网络层
  4. 链接层
  5. 实体层

HTTP协议

HTTP/0.9

发送

http
GET /index.html

接收

http
<html>
  <body>Hello World</body>
</html>

只能接收HTML格式

HTTP/1.0

发送

http
GET / HTTP/1.0
User-Agent: Mozilla/5.0 (Macintoch: Intel Mac OS X 10_10_5)
Accept: */*

接收

http
HTTP/1.0 200 OK
Content-Type: text/plain
Content-Length: 137582
Expires: <...>
Server: Apache 0.84
\r\n
<html>
  <body>Hello World</body>
</html>

\r\n代表空行

Content-Type (MIME type)
  • 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

HTTP1.0只能连接一个请求,为了解决这个问题,引入HTTP1.1。

二者最大的区别在于HTTP1.1引入了持久连接,默认Connection: keep-alive

HTTP1.1

特性

  • 持久连接

  • 管道机制

  • Content-Length字段

  • 分块传输编码

    Transfer-Encoding: chunked
    http
    HTTP/1.1 200 OK
    Content-Type: text/plain
    Transfer-Encoding: chunked
    
    25
    This is the data in the first chunk
    
    1C
    and this is the second one
    
    3
    con
    
    8
    sequence
    
    0

HTTP/2

一个彻底的二进制协议 头信息和数据体都是二进制,统称为“帧”

One day we will climb the highest mountain, and suvey the smallest point.