title: Angular 2 HTTP Post on Web API 2 - Bad Request
body: <p>I am trying to call web api authentication using angular 2 as below. But I am getting error</p>
  
  <p><strong>"Failed to load resource: the server responded with a status of 400 (Bad Request)"</strong></p>
  
  <p>The authentication service is running on local IIS server.</p>
  
  <p>Anything missing here?</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {Http, Response, RequestOptions, Request, RequestMethod, Headers, HttpModule} from '@angular/http';
  
  import { Observable } from 'rxjs/Observable';
  import 'rxjs/add/operator/map';
  
  
  
  @Injectable()
  export class AuthService {
      public token: string;
  
      constructor(private http: Http) {
          var currentUser = JSON.parse(localStorage.getItem('currentUser'));
          this.token = currentUser &amp;&amp; currentUser.token;
      }
  
      login(username, password): Observable&lt;boolean&gt; {
          var authObj = {
              username: username, Password: password, grant_type : 'password'
          }
  
          let headers = new Headers({ 'Content-Type': 'application/json' });
          let options = new RequestOptions({ headers: headers });
  
          return this.http.post('http://localhost/Authentication/oauth/Token', JSON.stringify({ username: username, Password: password, grant_type: 'password' }), options)
              .map((response: Response) =&gt; {
  
                  let token = response.json() &amp;&amp; response.json().token;
  
                  if (token) {
                      //set the token property 
                      this.token = token;
                      //user username and jwt token in local storage to keep user loggen in between page refreshes
                      localStorage.setItem('currentUser', JSON.stringify({ username: username, token: token }));
                      //return true to indicate the successful login
                      return true;
                  } else {
                      //return false to indicate failed login
                      return false;
                  }
              });
          }
  
      logout(): void {
          this.token = null;
          localStorage.removeItem('currentUser');
      }
  }
  </code></pre>