anjia / blog

博客,积累与沉淀
106 stars 4 forks source link

Part 1. HTTP:Web 的基础 #46

Open anjia opened 5 years ago

anjia commented 5 years ago

概述 HTTP 协议:Web 的基础构件、HTTP 的核心技术

  1. 第1章 HTTP 概述
  2. 第2章 URL 与资源
  3. 第3章 HTTP 报文
  4. 第4章 连接管理
anjia commented 5 years ago

第1章 HTTP 概述

Web 应用程序是如何使用 HTTP 进行通信的

1. HTTP - 因特网的多媒体信使

2. Web 客户端和服务器

3. 资源

anjia commented 5 years ago

HTTP,HyperText Transfer Protocol,超文本传输协议 TCP,Transmission Control Protocol,传输控制协议 IP,Internet Protocol,网际协议

DNS,Domain Name Service,域名服务


HTTP 网络协议栈
HTTP 应用层
TCP 传输层
IP 网络层
数据链路层
物理层

http://test.com:8888/jkzx/zx?kw=anjia&src=github#hello

window.location = {
   protocol: "http:",
    hostname: "test.com",   // 主机名,DNS -> IP
    port: "8888",
    host: "test.com:8888", // 主机
    origin: "http://test.com:8888",  // 源 -> 同源策略/跨域
    pathname: "/jkzx/zx",
    search: "?kw=anjia&src=github",
    hash: "#hello",
    href: "http://test.com:8888/jkzx/zx?kw=anjia&src=github#hello"  // ~完整~
}

步骤:

  1. 浏览器,IP + port -> 建立一条与服务器的 TCP 连接
    • URL -> hostname -> IP 地址
    • URL -> port
  2. 浏览器,发送 HTTP 请求报文
  3. 服务器,返回 HTTP 响应报文
  4. 关闭连接,浏览器显示 document

使用 Telnet

telnet test.com 80   <!--1. 建立 TCP 连接-->
Trying 111.222.333.444...
Connected to test.ss-lb.com.
Escape character is '^]'.
GET /index.html HTTP/1.1       <!--2. 输入 HTTP 请求 -->
Host: www.test.com
                       <!--请求结束,即空行的含义 -->
HTTP/1.1 404 Not Found  <!--3. 服务器的 HTTP 响应 -->
Server: openresty
Date: Fri, 25 Jan 2019 13:01:29 GMT
Content-Type: text/html
Content-Length: 162
Connection: close

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
Connection closed by foreign host.  <!--内容返回后,服务器会关闭连接 -->

说明:

telnet netcat

zzz6519003 commented 4 years ago

HTTP 网络协议栈 为啥要分五层 好多