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,
i tried with the commandprompt (curl -X POST localhost... -d ... ) and with the chrome extention 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):
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.