1

I am still somewhat new to Angular, but I am trying to send a post login request through an API backend (I am building the front end).

So, the API documentation is like this:

curl "URL" -d'user[email]=some%40email.com&user[password]=password&user[password_confirmation]=password' -X POST \ -H "Accept: application/something" \ -H "Content-Type: application/x-www-form-urlencoded"

This is my form:

  <form ng-submit='submit()' class='login-form'>
        <a ng-href='#/signup'><span class='md-text'>Signup</span></a>
        <span class='md-text'>|</span>
        <a><span class='md-text'>Forgotten password?</span></a>
        <input class='login-input' type='text' ng-model='username' placeholder='&#61447; Username'>
        <input class='login-input' type='password' ng-model='password' placeholder='&#xf023; Password'>
        <button type="submit" class="btn btn-primary btn-login" ng-model='submit'>Login</button>
  </form>

And this is part of my controller:

$scope.submit=function() {
  console.log('Submit');

  var reqLogin = {
    method: 'POST',
    url: 'URL',
    headers: {
      'Accept': 'application/blah,
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  }

  $http(reqLogin).success(function(response) {
    console.log(response);
  });
}

This may be a silly question, but I know to add the headers in angular, I do so in that JSON object I have above.

How do I add the -d portion to my HTTP request?

Tulun
  • 469
  • 4
  • 15

1 Answers1

-1

I was able to put the params in mixing jQuery.

      var reqLogin = {
        method: 'POST',
        url: 'URL',
    data: $.params({
"user[email]": email,
"user[password]": password
)},
        headers: {
          'Accept': 'application/blah,
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }
Tulun
  • 469
  • 4
  • 15