在 node.js 中使用 request.body 或 request.params 有什么区别吗? [英] Is there any difference between using request.body or request.params in node.js?

查看:22
本文介绍了在 node.js 中使用 request.body 或 request.params 有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道从客户端向服务器发送数据时在 node.js 中使用 request.body 或 request.params 是否有任何偏好?

I am wondering if there is any preference in using request.body or request.params in node.js when sending data from client to server?

推荐答案

与 url 相比,您可以在正文中容纳更多(不同的)数据.您可以在正文中传递任何字符串(特殊字符),而在 url 中对它们进行编码会使您容易受到状态 414(请求 URI 太长)的影响.并且在传递数组和复杂对象时使用主体要容易得多:)

You can fit more (diverse) data in the body than in the url. You can pass any string (special characters) in the body, while encoding them in the url would get you vulnerable to status 414 (Request-URI Too Long). And it's a lot easier to use the body when passing arrays and complex objects :)

这篇关于在 node.js 中使用 request.body 或 request.params 有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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