0

I'm pretty new to AngularJS, but for some reason i have to use it and create small web-page, to be able to sent some requests to my Web Api 2 part. I`m stuck with one strange error. My Controller is in ApplicationFrontEnd/MainView folder, file is called "main.js". Problem part of code :

    var request = {
        method: 'POST',
        url: 'api/login',
        headers: {
            'Authorization': 'Basic ' + encoded
        }
    }
    $http(request)
       .success(function (data, status, headers, config) {
          // I`m supposed to have no problem
       })
       .error(function (data, status, headers, config) {
           //but for some reason i do have.
       });

So, at the point of sending post request is sent not to 'api/login' , but to 'ApplicationFrontEnd/api/login', and do not have any Authorization header. On Web Api part of project i have CORS turned on, etc., but while i have wrong url in request, i receive 404 error (pretty logical). Can someone please explain to me, what i'm doing wrong and how to fix it?

2
  • Here docs.angularjs.org/api/ng/service/$http you can find a section about http headers. You will find Authentication under common ones. Commented Oct 20, 2015 at 18:50
  • @V_Maenolis thx, i saw it. Can you say anything about request uri deformation ? Commented Oct 20, 2015 at 18:55

1 Answer 1

1

Make the url absolute by adding a leading /

url: '/api/login'

Will make calls to http://yourDomain.com/api/login.

Sign up to request clarification or add additional context in comments.

2 Comments

THX! This leading / did the trick. Not obvious thing about absolute url (for me, at least).
i told i`m new to Angular. In .net there is kinda few properties in Uri class , and i can anytime check if my Uri is absolute. But in that JS - there is nothing like that, so that's was not obvious )

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.