0

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, …}

1 Answers1

1

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

  • Hmm, that's strange. They should be OK after the initial = that separates key and value, or you could try encoding them as %3D (i.e. [encode as an URL component](https://stackoverflow.com/a/4550600/243245)). But if it works without, great. Sorry I didn't spot that back then! – Rup Mar 26 '19 at 16:03