不允许使用angularjs POST 405方法

时间:2016-02-05 16:43:54

标签: angularjs node.js oauth satellizer npm-liveserver

我有一个 angularjs 项目,其中包含对github的oauth。

我使用satellizer plugin来处理oauth协议。

每次我尝试连接时都会收到此错误:

enter image description here

这是我的路线配置(它使用Babel的ES6):

export default function RouteConfig($routeProvider, $locationProvider) {

 $routeProvider
    .when('/', {
        templateUrl: './modules/default/default.html',
        controller: 'DefaultController',
        controllerAs: 'default'
    })
    .when('/auth/:provider',{
        controller: 'OAuthController',
        templateUrl: './modules/auth/auth.html',
    })
    .otherwise({
        redirectTo: '/'
    });
}

我使用Postman测试了应用程序,所有GET请求都正常,但每个POST请求都返回405.

我使用live-server来托管我的angularJS应用程序。我读过这个问题可能与服务器有关。我怎么解决这个问题?

我还使用 npm 来处理这些包。

**编辑:**我试过simplehttpserver这就是我得到的:

enter image description here

2 个答案:

答案 0 :(得分:1)

好像你在应用程序的某个地方做了一个http POST调用。 并将此请求发送至

http://localhost:8080/src/auth/callback

因为似乎没有服务器监听 - 或者至少没有POST请求。可能您需要在代码中找到http请求,并检查您是否使用了正确的网址来表示您的请求

答案 1 :(得分:-1)

我终于想通了。 AngularJS无法处理POST请求,服务器负责这样做,我忘了启动并为服务器添加代码。

对于那些与我有同样问题的人,可以在这里找到例子:

https://github.com/sahat/satellizer/tree/master/examples