You can use the querystring
module:
(您可以使用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.
});
}
}
Now, for example, if you have an input
field with name age
, you could access it using the variable post
:
(现在,例如,如果您有一个名为age
的input
字段,则可以使用变量post
访问:)
console.log(post.age);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…