body-parser - 扩展选项(qs 与查询字符串)
body-parser - extended option (qs vs querystring)
在 body-parser 的当前版本中,现在需要使用 bodyParser.urlencoded()
时的 extended
选项。在自述文件中,它解释了:
The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true).
[...]
Defaults to true, but using the default has been deprecated. Please research into the difference between qs and querystring and choose the appropriate setting.
我找不到任何有用的或具体的信息。我只找到了一个已弃用的 node-querystring.
这个选项应该永远为真吗?
此消息的原因是 body-parser
是 about to change default value for extended
from true
to false
。
扩展协议使用qs
library解析x-www-form-urlencoded
数据。 qs
的主要优点是它使用了非常强大的 serialization/deserialization 算法,能够序列化任何类似 json 的数据结构。
但是网络浏览器通常不使用此协议,因为 x-www-form-urlencoded
旨在序列化平面 html 表单。不过,如果您要使用 ajax
.
发送丰富的数据结构,它可能会派上用场
querystring
library` 提供基本的 serialization/deserialization 算法,所有网络浏览器都使用该算法来序列化表单数据。这种基本算法比扩展算法简单得多,但仅限于平面数据结构。
两种算法对平面数据的处理完全相同。
现在,当您了解这两种算法的优缺点后,您就可以决定哪种算法更适合您的应用程序了。
在 body-parser 的当前版本中,现在需要使用 bodyParser.urlencoded()
时的 extended
选项。在自述文件中,它解释了:
The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true).
[...]
Defaults to true, but using the default has been deprecated. Please research into the difference between qs and querystring and choose the appropriate setting.
我找不到任何有用的或具体的信息。我只找到了一个已弃用的 node-querystring.
这个选项应该永远为真吗?
此消息的原因是 body-parser
是 about to change default value for extended
from true
to false
。
扩展协议使用qs
library解析x-www-form-urlencoded
数据。 qs
的主要优点是它使用了非常强大的 serialization/deserialization 算法,能够序列化任何类似 json 的数据结构。
但是网络浏览器通常不使用此协议,因为 x-www-form-urlencoded
旨在序列化平面 html 表单。不过,如果您要使用 ajax
.
querystring
library` 提供基本的 serialization/deserialization 算法,所有网络浏览器都使用该算法来序列化表单数据。这种基本算法比扩展算法简单得多,但仅限于平面数据结构。
两种算法对平面数据的处理完全相同。
现在,当您了解这两种算法的优缺点后,您就可以决定哪种算法更适合您的应用程序了。