title: Angular.js 401 Unauthorized Status Code
body: <p>I want to get access token for authentication. My post result like </p>
  
  <p>POST <a href="https://staj-io-goldenilkay92-1.c9.io/api/v1/oauth/token" rel="nofollow noreferrer">https://staj-io-goldenilkay92-1.c9.io/api/v1/oauth/token</a> 401 (Unauthorized)</p>
  
  <p>but when I try to post with postman it works.</p>
  
  <p><strong>Server Side Headers</strong></p>
  
  <pre><code>res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
  res.setHeader('Access-Control-Allow-Credentials', 'true');
  res.header('Content-Type', 'application/json');
  </code></pre>
  
  <p><strong>Angular Code</strong></p>
  
  <p><em>Service</em></p>
  
  <pre><code>function signIn(data) {
  
      var deferred = $q.defer();
  
  
      $http.post('https://staj-io-goldenilkay92-1.c9.io/api/v1/oauth/token', data,
          {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}
      )
          .success(function (response, status, headers, config) {
              deferred.resolve(response);
          }).error(function () {
              deferred.reject("Failed to login");
          });
  
      return deferred.promise;
  
  }
  </code></pre>
  
  <p><em>controller</em></p>
  
  <pre><code>  vm.loginData = {
  
      'client_id': 'client',
      'client_secret': 'client',
      'grant_type': 'password',
      'username': '',
      'password': ''
  };
  
  
  vm.login = function login() {
  
      loginService.signIn(vm.loginData).then(function (result) {
              vm.signInResult = result;
  
          },
          function (data) {
  
          });
  
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/hLHAW.png" alt="Postman Result"></p>
  
  <p>POST <a href="https://staj-io-goldenilkay92-1.c9.io/api/v1/oauth/token" rel="nofollow noreferrer">https://staj-io-goldenilkay92-1.c9.io/api/v1/oauth/token</a> 401 (Unauthorized)</p>