HTTP 简介

234 阅读1分钟

HTTP 请求格式

1 动词 路径 协议/版本

2 Key1: value1

2 Key2: value2

2 Key3: value3

2 Content-Type: application/x-www-form-urlencoded

2 Host: www.baidu.com

2 User-Agent: curl/7.54.0

3

4 要上传的数据

使用 Chrome 查看 http 请求头

  1. 打开 Chrome
  2. 打开 inspector
  3. 输入网址
  4. 点击 network
  5. 找对对应的请求
  6. 点击 view source

http_response_header

HTTP 响应格式

1 协议/版本号 状态码 状态解释

2 Key1: value1

2 Key2: value2

2 Content-Length: 17931

2 Content-Type: text/html

3

4 要下载的内容

http_request_header

curl 的使用

  1. GET 请求

curl -s -v -H -- "https://www.baidu.com"

请求内容为:

  1. POST 请求

curl -X POST -s -v -H -- "https://www.baidu.com"

请求内容为:

curl -X POST -d "123456789" -s -v -H -- "https://www.baidu.com"

curl 参数含义可以访问 curl 来查看。