HTTP 的做用就是指导浏览器和服务器如何进行沟通。今天,咱们就HTTP的请求与响应,作出简短的介绍。html
这里使用 curl 命令来实现请求
请求示例1:
浏览器
curl -s -v -H "TEST: test" -- "https://www.baidu.com"
复制代码
curl -X POST -d "1234567890" -s -v -H "Test: test" -- "https://www.baidu.com"
复制代码
GET / HTTP/1.1
Host: www.baidu.com
User-Agent: curl/7.54.0
Accept: */*
TEST: test
复制代码
打开 Network
地址栏输入网址
在 Network 点击,查看 request,点击「view source」
能够看到请求的前三部分
若是有请求的第四部分,那么在 FormData 或 Payload 里面能够看到
bash
以上面两个请求为示例,咱们截取获得的响应 (以<开头):
第一个:
服务器
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 2443
Content-Type: text/html
Date: Wed, 05 Dec 2018 12:10:46 GMT
Etag: "58860429-98b"
Last-Modified: Mon, 23 Jan 2017 13:24:57 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<!DOCTYPE html> ... 省略
复制代码
第二个:
app
HTTP/1.1 302 Found
Connection: Keep-Alive
Content-Length: 17931
Content-Type: text/html
Date: Wed, 05 Dec 2018 12:42:04 GMT
Etag: "54d9748e-460b"
Server: bfe/1.0.8.18
<html> ... 省略
复制代码
能够看出响应的格式为:
1 协议/版本号 状态码 状态解释
2 Key1: value1
2 Key2: value2
2 Content-Length: 17931
2 Content-Type: text/html
3
4 要下载的内容
状态码是服务器对浏览器说的话,能够查阅或记忆
状态解释没什么用
第 2 部分中的 Content-Type 标注了第 4 部分的格式
第 2 部分中的 Content-Type 遵循 MIME 规范
dom
打开 Network
输入网址
选中第一个响应
查看 Response Headers,点击「view source」
你会看到响应的前两部分
查看 Response 或者 Preview,你会看到响应的第 4 部分
curl
Email : singlesaulwork@gmail.com工具