4
Hello, I have a POST request that is content-type: x-www-form-urlencoded.
I need to pass some parameters on my Body, this way:
I’m doing this way below to add my parameters on the request body:
ObtendoToken(): Observable<string> {
const headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded')
const body = new URLSearchParams();
body.set('grant_type', 'password');
body.set('username', 'varejo_user');
body.set('password', 'w6h5xgtl');
return this.http.post(`${ApiDeSegurança}`, body, new RequestOptions({headers: headers})).map(response => response.json());
}
But this error is returning:
error":"unsupported_grant_type
I believe it is in the creation of the body parameters. I am not able to solve, as it is my first POST request at the angle!
Thank you in advance....
I restarted my angular application and tried to use the same method and the error occurred again...
New method with the same error as: unsupported_grant_type
ObtendoToken(): Observable<string> {
const headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
const body = {grant_type: 'password', username: 'varejo_user', password: 'w6h5xgtl'};
return this.http.post(`${ApiDeSegurança}`, body, new RequestOptions({headers: headers})).map(response => response.json());
}
tries to create an object with body... body = { grant_type : 'password' , username: 'retail user' , password: 'w6h5xgtl' } ;
– Lucas Brogni
It worked 100%! if you want to create an answer I approve from here! thank you very much...
– Guilherme Nunes
Show ! I’ll put it there. It was nothing :)
– Lucas Brogni
Lucas I restarted, my angular application and tried to perform the same code and again gave the same error.... I will add the new method in the question...
– Guilherme Nunes