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:

  1. arraybuffer

  2. blob

  3. formdata

  4. json

  5. 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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -