javascript - Send code via post message is not working -
i wanted send code node application , use postman post message , in body put following:
module.exports = function() { var express = require('express'), app = express(); app.set('port', process.env.port || 3000); return app; } in header of request put
content-type application/text/enriched in node code use following
module.exports = function (app) { fs = require('fs'); var bodyparser = require('body-parser'); ... app.post('/bb',function(req,res){ var filecontent = req.body and file content empty ,i able see works since stops in debug
if want add custom content type need keep 2 things in mind:
- content type couldn't "application/text/enriched", in other hand "application/text-enriched" ok. max 2 "words".
- you must provide custom accept header on body parser configuration body parser return buffer when use custom header
see example:
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 string', req.body.tostring()) res.status(200).send('ok'); }); app.listen(3000); you can test in console curl:
curl 'http://localhost:3000/demo' -d 'name=john&surname=doe' -h 'content-type: application/text-enriched' i recommend try not use custom content type header because things easier. hope explanation you.
Comments
Post a Comment