[英]node.js mongodb express - cannot POST/
var express = require('express');
var mongoUtils = require('./mongooseData.js')
var app = express();
app.get('/businesses' , mongoUtils.findAllBusinesses);
app.post('/newBusiness' , mongoUtils.enterNewBusiness);
app.listen(3000);
this is the server, i dont know why but the GET is working but the POST isn't, 这是服务器,我不知道为什么,但是GET有效,但POST不起作用,
i tried with the commandprompt (curl -X POST localhost... -d ... ) and with the chrome extention REST 我尝试使用commandprompt(curl -X POST localhost ... -d ...)和Chrome扩展REST
and i still getting the Cannot POST/ 而且我仍然无法发布/
the reply from the node server is "OK" and printing to the console 来自节点服务器的答复为“确定”,并打印到控制台
The problem could be that you are not processing the response properly. 问题可能是您没有正确处理响应。
I tried this and worked (with express 4.8.5): 我尝试了这个并工作(使用Express 4.8.5):
var express = require('express');
var log = function(req, res, next) {
console.log('Logging');
res.end();
};
var app = express();
app.get('/businesses' , log);
app.post('/newBusiness' , log);
app.listen(3000);
and got: 并得到:
$ curl -i localhost:3000/businesses
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 0
ETag: W/"0-0"
Date: Tue, 19 Aug 2014 12:45:14 GMT
Connection: keep-alive
$ curl -X POST -i localhost:3000/newBusiness
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 0
Date: Tue, 19 Aug 2014 12:45:17 GMT
Connection: keep-alive
Make sure that you have res.send
, res.end
, res.status
or similar. 确保您具有
res.send
, res.end
, res.status
或类似名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.