body-parser - 扩展选项(qs vs querystring) [英] body-parser - extended option (qs vs querystring)

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

问题描述

在当前版本的正文解析器中,扩展选项当使用 bodyParser.urlencoded()现在需要。在README中,它解释:

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


扩展选项允许在将URL编码数据与querystring库进行解析之间进行选择(如果为false)或者qs库(如果为真)

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.

我找不到任何有用的或具体的信息。我只发现一个已弃用的节点查询字符串

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 即将更改默认值扩展 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 library` 提供基本的序列化/反序列化算法,所有网络浏览器使用的序列化表单数据。这个基本算法比扩展的算法要简单得多,但局限于平面数据结构。

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 querystring)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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