node使用了express4和body-parser来解析php curl的数据,但是获取的req.body是{},设置了header
前提知识:
body-parser不支持解析multi/form-data的功能,如果是传递二进制数据或者文件上传,就不能用它了。
Node.js body parsing middleware.
This does not handle multipart bodies, due to their complex and typically large nature. For multipart bodies, you may be interested in the following modules:
busboy and connect-busboy
multiparty and connect-multiparty
formidable
multer
This module provides the following parsers:
JSON body parser
Raw body parser
Text body parser
URL-encoded form body parser
参考:
https://github.com/expressjs/body-parser#bodyparserurlencodedoptions
PHP 代码
// determine if request should be parsed
if (!shouldParse(req)) {
return ('skip parsing'), next()
}
这行shouldParse 返回false
再到type-is.js/index.js 返回false。
var value = req.headers['content-type']
function typeofrequest(req, types_) {
var types = types_
// no body
if (!hasbody(req)) {
return null
}
// support flattened arguments
if (arguments.length > 2) {
types = new Array(arguments.length - 1)
for (var i = 0; i < types.length; i++) {
types = arguments[i + 1]
}
}
// request content type
var value = req.headers['content-type']
return typeis(value, types)
}