Handling text/plain in Express (via connect)?

前端 未结 5 790
轻奢々
轻奢々 2020-12-15 01:37

I am using Express 3, and would like to handle text/plain POSTs.

Express 3 uses connect\'s bodyParser now (I think the old Express code got moved t

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 02:22

    https://gist.github.com/3750227

    app.use(function(req, res, next){
      if (req.is('text/*')) {
        req.text = '';
        req.setEncoding('utf8');
        req.on('data', function(chunk){ req.text += chunk });
        req.on('end', next);
      } else {
        next();
      }
    });
    

    Will add the text as req.text

提交回复
热议问题