如何處理Node.js中的POST數(shù)據(jù)?如何提取表單數(shù)據(jù)(form[method="post"])和從HTTP發(fā)送的文件上載POST方法Node.js?我看過文檔,谷歌了一下,什么也沒找到。function (request, response) {
//request.post????}有圖書館還是黑客?
3 回答

一只萌萌小番薯
TA貢獻1795條經(jīng)驗 獲得超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. }); }}
input
age
post
:
console.log(post.age);

收到一只叮咚
TA貢獻1821條經(jīng)驗 獲得超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 關(guān)注
- 1028 瀏覽
添加回答
舉報
0/150
提交
取消