Hi,
I am using the following code to get an access token from the back-end server that runs on Azure. But I receive 400 Bad Request error. I am pretty sure I am sending wrong encoded data but don’t know how to fix it. Any help really appreciated.
router.services.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Login } from '../user/Login';
import { puts } from 'util';
const httpOptions = {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
};
@Injectable({
providedIn: 'root'
})
export class RouterService {
[x: string]: any;
private url = "http://___.azurewebsites.net";
constructor(private http: HttpClient) { }
async login(user: Login) {
return this.postUrl("/token", user);
}
async register(user) {
return this.postUrl("user/create", user);
}
private async getUrl(path: string) {
return new Promise((resolve) => {
this.http.get(this.url + path).subscribe((data) => {
console.log(data);
resolve(data);
});
});
}
private async postUrl(path: string, post: any) {
console.log(this.url, path, post);
return new Promise((resolve) => {
this.http.post(this.url + path, post).subscribe((data) => {
resolve(data);
});
});
}
Part of login.page.ts code
export class LoginPage implements OnInit {
private user: Login = {
username: '',
password: '',
grant_type: "password"
}