I am trying to post data from Angular4 on localhost:4200 to an API on localhost:8000. I works fine with Postman, but not with Angular. Then I get:
Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)
This is the service that posts to api:
@Injectable()
export class ApiService {
    constructor(private http: Http) { }
    login(username: string, password: string): Observable<Response>{
        const url = 'http://localhost:8000/login';
        const json = JSON.stringify({username: username, password: password});
        const headers: Headers = new Headers();
        headers.append('Content-Type', 'application/json; charset=UTF-8');
        return this.http.post(url, json, headers )
            .map(res => res.json());
    }
}
This is the code that runs the method
   logIn(user: string, password: string){
      this.apiService.login(user, password).subscribe(
          data => console.log(data),
          error => console.log(error)
      );
    }