You’re posting JSON data to the API instead of form data.
The snippet below should work.
login(username, password): Observable<any> {
const body = new HttpParams()
.set('username', username)
.set('password', password);
return this.http.post('/login',
body.toString(),
{
headers: new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
}
);
}