不管是作为后端还是前端开发人员,对于web请求的过程和参数都是需要了解的。
下面是对一次简单的http请求的header分析,作为自己的一个总结,也希望对大家有所帮助。
以chrome为例:
我们对header的参数挨个分析
general
需要注意的地方:锚点(永远不会发到服务器端)
uri和url的区别:url是uri最常见的一种形式,url的协议(http/https/ssh/ftp/wss/mailto)
请求方法除了常见的get,post,put,delete,还包括如下:
head,connect,patch,options,trace
参考:https://developer.mozilla.org/zh-cn/docs/web/http/methods
状态码需要了解的大致如下: 1xx:服务器收到信息,等待请求者继续(100:contine,101:协议切换) 2xx:接受并操作成功(200,201:created,202:accepted-可能交给其它进程处理,203 non-authoritative information,204:no content, 205:reset content,206:partial content) 3**:重定向(300 multiple choice,301 moved permanently,302 found,303 see other,304 not modified,305 use proxy, 306 unused,307 temporary redirect,308 permanent redirect) 4xx:客户端错误(400 bad request-语义有错或参数错误,401 unauthorized,402 payment required-备用,403 forbidden-类似权限禁止,404 not found, 405 method not allowed,406 not acceptable,407 proxy authentication required,408 request timeout,409 conflict,410 gone, 411 length required,412 precondition failed,413 payload too large,414 uri too long,415 unsupported media type, 416 requested range not satisfiable,417 expectation failed,418 i'm a teapot-好玩,421 misdirected request, 422 unprocessable entity (webdav),423 locked (webdav),424 failed dependency (webdav),425 too early, 426 upgrade required,428 precondition required,429 too many requests,431 request header fields too large, 451 unavailable for legal reasons) 5xx:服务器错误(500 internal server error,501 not implemented,502 bad gateway,503 service unavailable,504 gateway timeout, 505 http version not supported,506 variant also negotiates,507 insufficient storage,508 loop detected (webdav), 510 not extended,511 network authentication required)
参考:https://developer.mozilla.org/zh-cn/docs/web/http/status
我们对header的一个个参数分析
接下来是response header
no-cache:强制确认缓存,也就是说向服务器确实是否有缓存(使用服务器端缓存则304)
no-store:禁止进行缓存
private:私有(同一用户)
public:共有
max-age:缓存过期机制(秒数)- 如果没有此参数则会检查expires属性,如果expires也没有,则检查last modified
must-revalidate:使用陈旧资源时必须向服务器验证(缓存驱逐了解下)
* 关于缓存,非常重要,详情可参考这里
close: http1.0默认 keep-alive: http1.1默认,持久连接 (对于keep-alive的信息,在服务器设置max和timeout,分别标示最大请求数,超时时间)
* 所谓长连接是指tcp连接会保持一定时间不关闭
结构:type/subtype;parameter=value,例如:text/plain;charset=utf-8
分为两种:discrete types和multipart types
比较重要的类型如下:
application/octet-stream:默认二进制文件(未知),一般用作下载文件(和content-disposition:attachment一起用)
text/plain,text/css,text/html,text/javascript
multipart/form-data
详情参考
接下来是request header
告知服务器客户端可以处理的类型
<mime_type>/<mime_subtype> 单一精确的 mime 类型, 例如text/html.
<mime_type>/* 一类 mime 类型, 但是没有指明子类。 image/* 可以用来指代 image/png, image/svg, image/gif 以及任何其他的图片类型。
*/* 任意类型的 mime 类型
;q= (q因子权重)
值代表优先顺序,用相对质量价值表示,又称作权重。
对应response的content-type
accept-encoding: gzip, deflate, br (编码格式,一般是压缩类型,对应response的content-encoding。用identity可以禁止压缩)
客户端可理解的自然语言和优先选择的区域
zh-cn是区域,zh是语言,;q是权重
基本和response中的cache-control对应
如下指定可禁止缓存:
cache-control: no-cache, no-store, must-revalidate
用来让网络协议的对端来识别发起请求的用户代理软件的应用类型、操作系统、软件开发商以及版本号
web浏览器的格式一般如下:
mozilla/<version> (<system-information>) <platform> (<platform-details>) <extensions>
详情参考
如对本文有疑问, 点击进行留言回复!!
网友评论