如何解决状态码:使用$ http.post不允许405方法?

时间:2016-05-27 01:40:27

标签: angularjs node.js express

我的角度客户端有一个如下所示的postrequest:

$http.post("api/login/",  { foo: 'bar' }).success(function(data, status) {
                $scope.hello = data;
})

服务器以express:

实现
var express = require('express');

var app = express();

var bodyParser = require('body-parser');

var cors = require('cors');
var express = require('express');

var request = require('request');

app.set('port', process.env.PORT || 3000);
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/api/login', function(req, res) {
    res.send({message:'hello from api/login'});

});

app.listen(app.get('port'), function() {
    console.log('Express server listening on port ' + app.get('port'));
});

当我点击“登录”时出现错误:

Status Code:405 Method Not Allowed

如何解决此错误? github上:https://github.com/dimitri-a/oauth_stuff

0 个答案:

没有答案