body-parser - 扩展选项(qs vs 查询字符串) [英] body-parser - extended option (qs vs querystring)

查看:29
本文介绍了body-parser - 扩展选项(qs vs 查询字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前版本的body-parser中,使用extended选项>bodyParser.urlencoded() 现在是必需的.在自述文件中,它解释了:

In the current version of body-parser, the extended option when using bodyParser.urlencoded() is now required. In the README, it explains:

扩展选项允许在使用查询字符串库(当为假)或 qs 库(当为真)解析 URL 编码数据之间进行选择.

The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true).

[...]

默认为 true,但不推荐使用默认值.请研究 qs 和 querystring 的区别并选择合适的设置.

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.

I couldn't find any helpful or specific information on this. I only found a deprecated node-querystring.

这个选项应该总是正确的吗?

Should this option just always be true?

推荐答案

这个消息的原因是 body-parser即将将 extended 的默认值从 true 更改为 false.

The reason for this message is that body-parser is about to change default value for extended from true to false.

扩展协议使用qs来解析x-www-form-urlencoded 数据.qs 的主要优点是它使用了非常强大的序列化/反序列化算法,能够序列化任何类似 json 的数据结构.

Extended protocol uses qs library to parse x-www-form-urlencoded data. The main advantage of qs is that it uses very powerful serialization/deserialization algorithm, capable of serializing any json-like data structure.

但网络浏览器通常不使用此协议,因为 x-www-form-urlencoded 旨在序列化平面 html 表单.不过,如果您要使用 ajax 发送丰富的数据结构,它可能会派上用场.

But web-browsers don't normally use this protocol, because x-www-form-urlencoded was designed to serialize flat html forms. Though, it may come in handy if you're going to send rich data structures using ajax.

querystring 库` 提供了基本的序列化/反序列化算法,所有网络浏览器都使用一种来序列化表单数据.这种基本算法比扩展算法简单得多,但仅限于平面数据结构.

querystring library` provides basic serialization/deserialization algorithm, the one used by all web-browsers to serialize form data. This basic algorithm is significantly simpler than extended one, but limited to flat data structures.

对于平面数据,两种算法的工作原理完全相同.

Both algorithms work exactly the same with flat data.

现在,当您了解了两种算法的优缺点后,就可以决定哪一种更适合您的应用了.

Now, when you know pros and cons of both algorithms, it's up to you to decide which one suits your application better.

这篇关于body-parser - 扩展选项(qs vs 查询字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆