如何处理Node.js中的POST数据?如何提取表单数据(form[method="post"])和从HTTP发送的文件上载POST方法Node.js?我看过文档,谷歌了一下,什么也没找到。function (request, response) {
//request.post????}有图书馆还是黑客?
3 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
querystring
var qs = require('querystring');function (request, response) {
if (request.method == 'POST') {
var body = '';
request.on('data', function (data) {
body += data;
// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6)
request.connection.destroy();
});
request.on('end', function () {
var post = qs.parse(body);
// use post['blah'], etc.
});
}}inputagepost:
console.log(post.age);
收到一只叮咚
TA贡献1821条经验 获得超5个赞
var qs = require('querystring');function (request, response) {
if (request.method == 'POST') {
var body = '';
request.on('data', function (data) {
body += data;
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6) {
// FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST
request.connection.destroy();
}
});
request.on('end', function () {
var POST = qs.parse(body);
// use POST
});
}}- 3 回答
- 0 关注
- 1051 浏览
添加回答
举报
0/150
提交
取消
