HTTP 协议基础

HTTP 协议报文格式

图片来自 HTTP协议浅析(中):请求报文和响应报文

  • 请求报文
http_request.jpg
  • 响应报文
http_response.png

HTTP Satus Code

3xx Redirection

  • 304: NOT MODIFIED
    A conditional GET or HEAD request has been received and would have resulted in a 200 OK response if it were not for the fact that the condition evaluated to false.

4xx: Client Error

  • 401: UNAUTHORIZED
    The request has not been applied because it lacks valid authentication credentials for the target resource.

  • 404: NOT FOUND
    The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

  • 405: METHOD NOT ALLOWED
    The method received in the request-line is known by the origin server but not supported by the target resource. (对于请求所标识的资源,不允许使用请求行中所指定的方法。)

  • 407: PROXY AUTHENTICATION REQUIRED
    Similar to 401 Unauthorized, but it indicates that the client needs to authenticate itself in order to use a proxy.

HTTP Methods

POST

HTTP headers

Etag

Etag(Entity tag) 具体解释: 什么是ETag

Tornado/1.1 web.py 源码:

            if (self._status_code == 200 and self.request.method == "GET" and
                "Etag" not in self._headers):
                hasher = hashlib.sha1()
                for part in self._write_buffer:
                    hasher.update(part)
                etag = '"%s"' % hasher.hexdigest()
                inm = self.request.headers.get("If-None-Match")
                if inm and inm.find(etag) != -1:
                    self._write_buffer = []
                    self.set_status(304)
                else:
                    self.set_header("Etag", etag)

location

跳转(重定向)
当浏览器接受到头信息中的 Location: xxxx 后,就会自动跳转到 xxxx 指向的URL地址.
例如,

header["location"] =  "http://www.baidu.com/"

keep-alive

具体阅读: HTTP Keep-Alive是什么?如何工作?

keep-alive

read more

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文整理自MIN飞翔博客 [1] 1. 概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或...
    HoyaWhite阅读 2,706评论 2 20
  • 概述 HTTP协议全称为超文本传输协议(HyperText Transfer Protocol),它使得网络上的W...
    WeberLisper阅读 1,165评论 1 1
  • HTTP协议 HTTP协议作为网络传输的基本协议,有着广泛的应用。 HTTP协议的完整内容很多,但是其核心知识却又...
    小甲鱼python阅读 382评论 0 1
  • HTTP的定义 Http(HyperText Transfer Protocol,超文本传输协议),是用于从万维网...
    不思则亡阅读 495评论 0 1
  • 我现在就开始期待冬天了,嘿嘿! 画完好几天的雪人今天可以出来见见人啦! 大家好,我还在绘画的康庄大道上,荆棘前行!
    anMoo韩魔阅读 307评论 4 6