通过邮件发送代码不起作用

我想发送代码给一些节点应用程序,我使用邮递员的邮件,并在我的身体,我把以下内容:

module.exports = function() { var express = require('express'), app = express(); app.set('port', process.env.PORT || 3000); return app; } 

在我要求的标题中

 content-Type application/text/enriched 

在节点代码中,我使用以下内容

 module.exports = function (app) { fs = require('fs'); var bodyParser = require('body-parser'); ... app.post('/bb',function(req,res){ var fileContent = req.body 

和文件内容是空的,我能够看到它的工作,因为它停在debugging

如果你想添加一个自定义的内容types,那么你需要记住两件事情:

  1. 内容types不能是“应用程序/文本/丰富”,另一方面“应用程序/文本丰富”是好的。 最多两个“单词”。
  2. 你必须在body parserconfiguration上提供一个自定义的accept头,但是当你使用自定义头时,body parser返回你一个缓冲区

看例子:

 var express = require('express') var app = express() var bodyParser = require('body-parser') app.use(bodyParser.raw({ type: 'application/text-enriched' })) app.post('/demo', function(req, res) { console.log('POST DATA') console.log('STREAM', req.body) console.log('STREAM to STRING', req.body.toString()) res.status(200).send('ok'); }); app.listen(3000); 

你可以在你的控制台用curl来testing:

 curl 'http://localhost:3000/demo' -d 'name=john&surname=doe' -H 'Content-Type: application/text-enriched' 

我build议你不要使用自定义的内容types头,因为事情比较容易。 我希望我的解释能帮助你。