Search code examples
asp.netangularaccess-token

error 400 bad request Angular 5 login with token


my service is:

 getToken(){
    var data = "grant_type=password&username=" + "username" + "&password=" + "yTX7W0s1zYxbJJT3+pXtJA==";

return this.http.post<any>('http://localhost:51643/token', data).pipe(map(res =>res))
}

for this example I use username e password static and in my componet

constructor(private data: PostaserviceService) { }
  ngOnInit() {  
     this.data.getToken().pipe().subscribe(res => {
      console.log(res);
    });
}

I have this error : POST http://localhost:51643/token 400 (Bad Request) ERROR HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "http://localhost:51643/token", ok: false, …}


Solution

  • I solved the problem was that I can't pass the special characters ==