0

I'm trying to make following http request using angularjs $http service

$http.get('http://myserver:8080/login?', {
            params:  {username: "John", password: "Doe" },
            headers: {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
        }).then(function(response) {
            alert('success');
            alert(response);
            }, function(x) {
              alert('err');
            });
        };

my server is up and runing and I'm getting following firebug console error enter image description here

So what I'm doing wrong here in sending http request?

3
  • Can you check the Request generated (via browser developer tools) ? Commented Jun 9, 2016 at 18:53
  • myserver:8080/login? i think your problem is here. Use relative path and remove "?" Commented Jun 9, 2016 at 18:55
  • 1
    Slightly unrelated but you should send login request as POST. GET parameters are always send in clear text over the network where POST parameters are encrypted if you're using HTTPS Commented Jun 9, 2016 at 18:56

1 Answer 1

1

Here is an example for send GET request using $http.get with params

$http.get('api/anyApi/get', { params: {name:name}})

As you see, you do not need absolute path and ? param to use.

Also, as jfadich mentioned - do not use GET for such requests.

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

2 Comments

please can you extend this with post example then, and with ?login as part of expected backend
My front part: return $http.get('api/anyApi/login', {params: {username: "John", password: "Doe" }, headers: {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}});

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.