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 to401 Unauthorized
, but it indicates that the client needs to authenticate itself in order to use a proxy.
HTTP Methods
POST
-
- application/x-www-form-urlencoded
- multipart/form-data
- application/json
- text/xml
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