在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中对它们进行编码会使您容易受到状态414(Request-URI Too Long)的攻击。在传递数组和复杂对象时使用正文要容易得多:)
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 :)