我正在尝试只处理简单的POST请求,并将数据附加到本地文件中。但是,当我尝试用邮递员发布原始文本(例如“ hi world”)时,实际添加的是[object Object]。我不确定如果没有任何内容解释为两端的对象,可能是什么原因引起的。谢谢!
[object Object]
var express = require('express'), fs = require('fs') url = require('url'); var app = express(); app.configure(function(){ app.use('/public', express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public')); app.use(express.bodyParser()); }); app.post('/receive', function(request, respond) { filePath = __dirname + '/public/data.txt'; fs.appendFile(filePath, request.body, function () { respond.end(); }); }); app.listen(8080);
var express = require('express'), fs = require('fs') url = require('url'); var app = express(); app.use('/public', express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public')); app.post('/receive', function(request, respond) { var body = ''; filePath = __dirname + '/public/data.txt'; request.on('data', function(data) { body += data; }); request.on('end', function (){ fs.appendFile(filePath, body, function() { respond.end(); }); }); }); app.listen(8080);