1

when I get a request from a url,like this:

    $http({
        method: 'GET',
        url:'http://mooc-lms.dev.web.nd/v0.3/users/login'
    }).success(function(data, status, headers, config) {
        //code
    });

But the error I get is:

    GET http://mooc-lms.dev.web.nd/v0.3/users/login 405 (Method Not Allowed)

However,if I change the method from "GET" to "POST",the error is:

    POST http://mooc-lms.dev.web.nd/v0.3/users/login 415 (Unsupported Media Type)

What's the problem?Is there something wrong with the url(http://mooc-lms.dev.web.nd/v0.3/users/login)? I find '"message":"Request method 'GET' not supported"' in the url.

2
  • If you have this error, it's probably because your server haven't any GET method implement on this url. Commented Aug 10, 2015 at 9:20
  • 1
    show us your back-end (no thats not dirty) we just need to see what your request is supposed to do. maybe you have not implemented it? Commented Aug 10, 2015 at 9:25

1 Answer 1

6

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 */
    }
})
Sign up to request clarification or add additional context in comments.

2 Comments

I am facing the similar error. I tried your solution but it didn't work for me. The URL gives response if I directly enter it in the url bar or through REST client also I am getting the data in the response. My server is set with Access-Control-Allow-Origin: *
The Access-Control-Allow-Origin header only impacts CORS. That's a totally separate thing. It sounds like you're not supposed to be POSTing. If you're hitting your resource through your URL bar and getting what you want, it sounds like you're just GETing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.