AngularJS: $http.get 405 (Method Not Allowed)

╄→гoц情女王★ 提交于 2019-12-02 07:37:52

The reason that GET isn't working is that the server doesn't support GET for the login endpoint, which is unsurprising. The most common reason for getting an HTTP 415 response on a POST request is because the server requires you to specify a Content-Type and/or Accept in your request header.

My example below sets them to application/json, which is common, but not ubiquitous, so you'll have to check what the server requires, and what it will give you back. Given that the address contains "mooc-lms", I assume you're doing some kind of online course. It should give you that information. That documentation should also tell you what data you need to send with the data property.

$http({
    method: 'POST',
    url: 'http://mooc-lms.dev.web.nd/v0.3/users/login',
    headers: {
        'Content-Type': 'application/json', /*or whatever type is relevant */
        'Accept': 'application/json' /* ditto */
    },
    data: {
        /* You probably need to send some data if you plan to log in */
    }
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!