0%

HTTP-基础

HTTP-基础

HTTP-基础

参考:https://www.w3.org/Protocols/

介绍:

规定了一种客户端与服务器端传输数据的方式。

  • 超文本传输协议

  • 无状态

  • 基于TCP/IP

1.0有三种请求方法。1.1增加了5种。

HTTP1.1内容

image-20200907183947988

http请求request

1
2
3
4
5
6
Client request:

GET /hello.txt HTTP/1.1
User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
Host: www.example.com
Accept-Language: en, mi

方法名称 /虚拟目录/文件名 协议名称/协议版本

用户代理:操作系统类型、版本,CPU类型,浏览器类型、版本,浏览器渲染引擎、浏览器语言

http响应response

1
2
3
4
5
6
7
8
9
10
11
Server response:

HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Accept-Ranges: bytes
Content-Length: 51
Vary: Accept-Encoding
Content-Type: text/plain

协议名称/版本 状态码

时间

服务器类型

最后修改时间

可用来查看访问资源是否改变

支持部分请求的标志

响应的字节长度

响应体类型

URL

HTTP使用统一资源标识符(Uniform Resource Identifiers, URI)来传输数据和建立连接。

http://blog.xiaoruiit.com:80/categories/git.html?id=1&page=1#name

  • 协议 http://
  • 域名或IP地址 blog.xiaoruiit.com
  • 端口 80
  • 虚拟目录 categories
  • 文件名 git.html
  • 参数 id=1&page=1
  • 锚 #name

状态码

2×× 成功

4×× 客户端找不到服务器

5×× 服务器端异常

请求方法

GET 查

POST 增

PUT 改

DELETE 删

工作原理

  1. 客户端连接到Web服务器
  2. 发送http请求
  3. 服务器接收请求并响应
  4. 释放连接
  5. 客户端解析响应的html内容