javascript - How to find the type of content inside req.body? -
as per https://developer.mozilla.org/en-us/docs/web/api/request/request type of body can of either type:
arraybuffer
blob
formdata
json
text
is there way receiving side know type is? reason ask since getting post message 3rd party req.body empty.
// code console.info("headers: ", req.headers); // shows headers console.log("data: ", req.body); // shows nothing
however, after further inspection, seems need process data follows (since using readablestream):
// code 3rd party library req.on('data', function (chunk) { data += chunk; }); req.on('end', function () { var messagedata = json.parse(data); console.log("data: ", messagedata); //shows data }
you could people use express , body parser library avoid having loads of boilerplate code parsing them.
wiki
Comments
Post a Comment