I have to pass query params to a post request in angular4 so i used HttpParams from angular 4 . This works fine with other post request but fails while accessing the authentication token from the backend. This is how the query params should look like
grant_type=password&username=username&password=password
so i tried like this
login(username: string, password: string) {
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('Accept', 'application/json');
let params = new HttpParams();
params = params.set('username', username);
params = params.set('password', password);
params = params.set('grant_type', 'password');
return this.http.post('////////////', {params: params},
{ headers: headers }).subscribe(data => {
console.log(data);
},
err => {
console.log('Error occured');
});
}