Request
我用 wireshark 工具分析了一个 HTTP 请求,可以看到大致的格式
其中HTTP的明文数据格式如下
GET URL HTTP/1.1\r\n // 请求行
Host: www.cnblogs.com\r\n // 请求头
Connection: keep-alive\r\n
Accept: application/json, text/javascript, */*; q=0.01\r\n
....
\r\n // 空行
data // 如果是 POST,可能有请求数据
Accept-Encoding
可接受的数据内容格式,比如是 gzip,服务器收到后根据这个使用 gzip 压缩数据,并在 Content-Encoding 中表明数据格式,这样客户端就可以接收到这个信息
Content-Encoding
发送的数据内容格式,比如是 gzip,服务器收到后根据这个使用 gzip 解压数据
Response
我用 wireshark 工具分析了一个 HTTP 响应请求,可以看到大致的格式
其中HTTP的明文数据格式如下
HTTP/1.1 200 OK\r\n // 响应行
Date: Wed, 22 Aug 2018 02:10:58 GMT\r\n // 响应头
...
\r\n // 空行
File Data: 5 bytes // 请求数据
Date
Example: Date: Tue, 15 Nov 1994 08:12:31 GMT
这个是属于服务器的时间,在RFC标准里面,服务器返回的数据中必须包含这个域,有三种情况除外
- If the response status code is 100 (Continue) or 101 (Switching Protocols), the response MAY include a Date header field, at the server's option 100 和 101 请求可选
- If the response status code conveys a server error, e.g. 500 (Internal Server Error) or 503 (Service Unavailable), and it is inconvenient or impossible to generate a valid Date. 服务器出现了问题,这时候也可以不能返回
- If the server does not have a clock that can provide a reasonable approximation of the current time, its responses MUST NOT include a Date header field. In this case, the rules is 服务器不能提供可靠的时间服务
Some origin server implementations might not have a clock available.An origin server without a clock MUST NOT assign Expires or Last-Modified values to a response, unless these values were associated
with the resource by a system or user with a reliable clock. It MAY assign an Expires value that is known, at or before server configuration time, to be in the past (this allows "pre-expiration" of responses without storing separate Expires values for each resource).