HTTP Cookie
来源:互联网 发布:网络电视如何使用 编辑:程序博客网 时间:2024/05/19 02:40
Cookie 的原理——生成和使用过程
Cookies are set using the HTTP Set-Cookie header, sent in an HTTP response. This header instructs the browser to store the cookie and send it back in future requests to the server (the browser will, of course, ignore this header if it does not support cookies or has disabled cookies).
1. The browser sends its first request to the homepage of the www.example.org website:
GET /index.html HTTP/1.1Host: www.example.org...
- The server responds with two Set-Cookie headers:
HTTP/1.0 200 OKContent-type: text/htmlSet-Cookie: theme=lightSet-Cookie: sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT...
The server’s HTTP response instructs the browser to set two cookies. The first, “theme”, is considered to be a “session” cookie, since it does not have an Expires or Max-Age attribute. Session cookies are intended to be deleted by the browser when the browser closes. The second, “sessionToken” contains an “Expires” attribute, which instructs the browser to delete the cookie at a specific date and time.
3. Next, the browser sends another request to visit the spec.html page on the website. This request contains a Cookie header, which contains the two cookies that the server instructed the browser to set.
GET /spec.html HTTP/1.1Host: www.example.orgCookie: theme=light; sessionToken=abc123...
This way, the server knows that this request is related to the previous one. The server would answer by sending the requested page, and possibly adding other cookies as well using the Set-Cookie header.
The value of a cookie can be modified by the server by including a Set-Cookie header in response to a page request. The browser then replaces the old value with the new value.
References
HTTP cookie
腾讯云-产品文档-cookie原理说明
- HTTP cookie
- HTTP cookie
- http cookie
- http cookie
- HTTP cookie
- HTTP-cookie
- http Cookie
- HTTP Cookie
- Http Cookie
- HTTP Cookie
- http cookie
- HTTP Cookie
- HTTP Cookie
- http cookie、flash cookie、evercookie
- HTTP中的Cookie
- HTTP的cookie处理
- HTTP 协议 Set-Cookie
- HTTP Cookie & Session
- 字符全排列
- MySQL学习13:操作数据表中的记录(一)
- jQuery打飞机游戏代码下载
- 2016"百度之星" - 资格赛(Astar Round1)Problem B(斐波那契数列)
- CSS 不规整元素的宽高等比例
- HTTP Cookie
- SDOI2016 Round2 退役记
- Android Studio和Eclipse有什么区别
- 全面理解iOS开发中的Scroll View
- ACM-–模拟打印–-湘大OJ 1086--菱形--水
- 最近的工作
- 《 常见算法与数据结构》符号表ST(3)——二叉查找树 (附动画)
- 取消activity的页面标题栏
- 浅谈编程中的学以致用