每个http的请求和响应都有同样的基本形式:一个首部行、一个包含元数据的Http首部、一个空行,然后是一个消息体
Http请求
GET /p/zfs HTTP/1.1
Host: www.oschina.net
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
Referer: http://www.oschina.net/news/71036/zfs-and-linux
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
第一行为请求行 包含一个方法、资源的路径和HTTP请求的版本
Http响应
http请求以一个空行结束(包括两个回车换行对 n)
当服务器看到这个空行,就开始通过同一个连接向客户端发送响应。http响应头如下
HTTP/1.1 200 OK
Date: Fri, 26 Feb 2016 13:28:36 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: Tengine
Vary: Accept-Encoding
Cache-Control: must-revalidate, no-cache, private
Expires: Sun, 1 Jan 2000 01:00:00 GMT
Pragma: no-cache
Content-Encoding: gzip