计网基础-Web应用之Http请求和响应消息格式
请求消息request
响应消息response
request
ASCII:人直接可读
示例:
GET http://www.new1.uestc.edu.cn/public/image/header_menu.png HTTP/1.1
Host: www.new1.uestc.edu.cn
Proxy-Connection: keep-alive
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://www.new1.uestc.edu.cn/public/UestcNews/dist/c5b9577e5d76a65d03b688041d94011f.css
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: ...
Q:既然已经和服务器建立起连接,为什么还需要声明访问的哪个主机(GET)吗?
A:在使用缓存、代理服务器的时需要用到这个声明。
http请求消息request的通用格式
EntityBody:当你通过POST方法,则需要在这个请求request中的body携带一些信息
如果输入信息比较少,则可以使用常见的GET方法,把信息放在URL里面上传
HTTP/1.1:get、post、head
HTTP/1.0:get、post、head、put、delete
response
示例:
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 19 Jun 2018 05:16:27 GMT
Content-Type: image/png
Content-Length: 246
Last-Modified: Wed, 08 Apr 2015 18:39:02 GMT
Connection: close
ETag: "552575c6-f6"
Expires: Thu, 19 Jul 2018 05:16:27 GMT
Cache-Control: max-age=2592000
Accept-Ranges: bytes
Proxy-Connection: keep-alive