Skip to content

Commit

Permalink
0901
Browse files Browse the repository at this point in the history
  • Loading branch information
lwstkhyl committed Sep 1, 2024
1 parent bb8f3f8 commit a7d2418
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions 01.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [http模块](#http模块)
- [HTTP基本概念](#http基本概念)
- [请求](#请求)
- [响应](#响应)

<!-- /code_chunk_output -->

Expand Down Expand Up @@ -710,3 +711,89 @@ HTTP(hypertext transfer protocol)**超文本传输协议**:对浏览器和服
- 之后的部分:请求体(不一定有)

![请求4](./md-image/请求4.png){:width=300 height=300}
**请求行**:由三部分组成——请求方法、url、HTTP版本号
![请求5](./md-image/请求5.png){:width=100 height=100}
- 请求方法:

| 方法 | 作用 |
| ------------ | -------- |
| GET(常用) | 获取数据 |
| POST(常用) | 新增数据 |
| PUT/PATCH | 更新数据 |
| DELETE | 删除数据 |

- URL(uniform resource locator)统一资源定位符,组成部分:(以https://www.baidu.com/为例)
- `https`:协议名,后面的`://`为协议的固定组成部分
- `www.baidu.com`:主机名,可以是这样的域名,也可以是`10.20.30.40`这样的IP地址
- 最后的`/`:路径,用于定位服务器中某部分的资源

![请求6](./md-image/请求6.png){:width=80 height=80}
- 端口号:http默认端口号是80,https默认端口号是443,如果使用指定协议的默认端口号就省略不写
- 查询字符串:向服务器传入额外的数据。它是键值对的形式,如上面的`keyword``psort`就是键,`oneplus``3`就是值,键值间以`=`连接,每个键值对间以`&`分隔
- HTTP版本号:
![请求7](./md-image/请求7.png){:width=100 height=100}

**请求头**:记录浏览器的相关信息。也是键值对的形式,如`Host`是键名,`www.baidu.com`是键值,键值间以`:`连接
- `User-Agent`:浏览器平台及版本号
- `Accept`:浏览器能处理的数据类型
- `Accept-Encoding`:浏览器支持的压缩方式
- `Accept-Language`:浏览器支持的语言
- `Connection: keep-alive`:保持连接通道,提高效率
- `Upgrade-Insecure-Requests: 1`升级HTTP协议为HTTPS,提高安全性
- 还会包括一些与请求头有关的内容
- [更详细的请求头内容介绍](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers)

**请求体**:内容格式非常灵活,可以设置任意内容
![请求8](./md-image/请求8.png){:width=80 height=80}
上图是一个登录请求的请求体,以键值对的形式发送了账号、密码等信息
![请求9](./md-image/请求9.png){:width=80 height=80}
如图,还可以是json的形式,这种方式较常用
###### 响应
响应报文与请求报文结构类似
![响应1](./md-image/响应1.png){:width=300 height=300}
**响应行**:由三部分组成——HTTP版本号、响应状态码、响应状态的描述
![响应2](./md-image/响应2.png){:width=80 height=80}
- HTTP版本号同[请求](#请求)
- 响应状态码:标识响应的结果状态

| 状态码 | 含义 |
| ------ | -------------- |
| 200 | 请求成功 |
| 403 | 禁止请求 |
| 404 | 找不到资源 |
| 500 | 服务器内部错误 |

响应状态码通过开头的数字进行分类:
| 状态码 | 含义 |
| ------ | -------------- |
| 1xx | 信息响应 |
| 2xx | 成功响应 |
| 3xx | 重定向消息 |
| 4xx | 客户端错误响应 |
| 5xx | 服务器错误响应 |

- 响应状态的描述:是一个字符串,绝大部分时候与响应状态码对应

| 状态码 | 状态描述 |
| ------ | --------------------- |
| 200 | OK |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Internal Server Error |

[更多的响应状态码和描述](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status)

**响应头**:记录与服务器相关的内容
- `Server`:服务器使用的技术
- `Date`:响应的时间
- `Content-Type`(重要):响应体内容的格式和字符集
- `Content-Length`:响应体内容的长度,单位是字节
- [更详细的响应头内容介绍](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers)
- 如果某个响应头不能在上面网站中搜索到,则可能是自定义的响应体

**响应体**:格式也很灵活,如HTMLCSS、js、图片、视频、json等
![响应3](./md-image/响应3.png){:width=300 height=300}
![响应4](./md-image/响应4.png){:width=80 height=80}
![响应5](./md-image/响应5.png){:width=200 height=200}
![响应6](./md-image/响应6.png){:width=80 height=80}
如图,除了最上面列举的HTML,也可以是CSS、js、图片、json等
Binary file added md-image/响应1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/响应2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/响应3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/响应4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/响应5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/响应6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/请求5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/请求6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/请求7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/请求8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added md-image/请求9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7d2418

Please sign in to comment.