Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
89
第 9 章
Cookie
和
Session
本章将学习如何使用
Cookie
和
Session
,通过跨页面甚至跨浏览器会话记住用户的偏好设
置,为他们提供更好的体验。
HTTP
是一个
无状态
协议。这意味着,如果你在浏览器上加载一个页面,再导航到同一个
网站的另一个页面,那么不管是服务器还是浏览器,都无法得知这是同一个浏览器在访问
同一个网站。换句话说,
每个
HTTP
请
求都包含着服务器要满足这个请求所需的全部信
息
,这也正是
We
b
的工作方式。
这的确是个问题。如果这个问题不能解决,我们将永远无法登入任何网页,流媒体将无法
工作,而网站也将不能跨页面记住你的偏好设置。因此,需要有一种在
HTTP
之上建立状
态的办法,这就是
Cookie
和
Session
出现的背景。
不幸的是,有人曾利用
Cookie
做了一些坏事
,让
Cookie
落得了个坏名声。这着实不幸,
因为
Cookie
对于
“现代网站”的正常运行确实至关重要(尽管
HTML5
已经引入了像本地
存储这样的新特性来达到相同的目的)。
Cookie
的想法很简单
:服务器发送一小段信息,然后浏览器存储一段时间(可配置)。这
一小段信息是什么实际由服务器决定,很多时候它只是一个唯一标识特定浏览器的
ID
,使
得状态得到维护。
关于
Cookie
,需要重点知道以下几点。
90
|
第
9
章
从用户角度来说, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099