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版)
78
第 8 章
表单处理
要采集用户提供的信息,通常做法就是使用
HTML
表单
。不管是让浏览器正常地提交表
单、使用
Ajax
,还是采用高级的前端控件
,底层的机制通常仍然是
HTML
表单。本章将
讨论表单处理、表单验证和文件上传的各种方法。
8.1
 把客户端数据发送到服务器
大体而言,把客户端数据发送到服务器有两种选择,即使用查询串和请求
body
。正常情
况下,如果使用查询串,就是发起
GET
请求;如果使用请求
body
,就是使用
POST
请求
(
HTTP
协议并不会阻止你反其道而行之,但这样做没什么意义,最好还是遵循标准实践)
。
常见的一种误解认为
POST
是安全的,而
GET
是不安全的。但实际上,如果使用
HTTPS
,
两者都是安全的;如果不使用
HTTPS
,则两者都不安全
。如果没有使用
HTTPS
,那么侵
入者查看一个
POST
请求的
body
数据就像查看
GET
请求的查询串一样容易。不过,如果使
用
GET
请求,你的用户就可以从查询串看到他们所有的输入(包括隐藏域),而这个查询
串又丑又乱。而且,通常浏览器对查询串的长度施加了限制(对请求的
body
则没有这样
的限制)。出于这些原因,我一般推荐使用
POST
做表单提交。
8.2
 
HTML
表单
本书主要关注服务器端,但了解一下
HTML
表单的构造也很有必要。下面是一个简单的
例子:
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