![](/img/trans.png)
[英]node.js body-parser bad interpretation of Content-Type:x-www-form-urlencoded and Form-data JSON
[英]node js how to identify postman extention client request came from “form-data” or “x-www-form-urlencoded”
我正在使用节点js,表达框架工作和rest api,我想知道邮递员扩展客户端请求来自“表单数据”或“ x-www-form-urlencoded”,我已经完成了基于“ x-www-此处使用“表单-urlencoded”选项可以直接获取值,例如req.headers.username或req.body.username或req.params.username。 但是在这种方法中的“表单数据”我无法直接获取值,例如req.headers.username或req.body.username或req.params.username。 所以我用下面的代码来获取值。
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
// `file` is the name of the <input> field of type `file`
console.log(files);
console.log('\n\n\n'+fields);
res.writeHead(200, {'content-type': 'text/plain'});
//res.write('received upload:\n\n');
res.send(util.inspect({fields: fields, files: files}));
});
因此,我要检查条件请求是否来自“表单数据”或“ x-www-form-urlencoded”,请帮助我。 也可以将form.parse字段值分配给req.body,因为我已经基于req.body编写了函数。
只需使用req.contentType。 它将为您提供请求内容类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.