HTTP 消息

HTTP使用客户端 - 服务器模型。

HTTP客户端打开连接并向HTTP服务器发送请求消息,然后服务器返回响应消息,通常包含所请求的资源。

HTTP请求消息

HTTP 请求消息 按给定顺序包含以下内容:

  1. 请求行:GET /xyz.html HTTP/1.1
  2. 主机名:Host www.example.com
  3. 可选标头:键值对,用冒号分割
  4. 一个空行
  5. 可选的请求体

例子:

1
2
3
4
5
6
7
8
9
10
11
GET / HTTP/1.1
Host: www.example.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,..
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/... Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
If-None-Match: "359670651+gzip"
If-Modified-Since: Fri, 09 Aug 2013 23:54:35 GMT

HTTP响应消息

HTTP 响应消息包含以下部分:

  1. 状态行:HTTP/1.1 OK
  2. 响应头:键值对
  3. 一个空行
  4. 响应体

例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
HTTP/1.1 304 Not Modified
Cache-Control: max-age=604800
Date: Mon, 01 Feb 2016 08:44:57 GMT
Etag: "359670651+gzip"
Expires: Mon, 08 Feb 2016 08:44:57 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (ftw/FBE4)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1

<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.....
<body>
.....
.....
</body>
</html>
0%