I have a problem, when I need to insert user to Keycloak I have this error :
message : "Http failure response for http://localhost:8080/auth/admin/realms/demo/clients: 415 Unsupported Media Type" name : "HttpErrorResponse" ok : false status : 415 statusText : "Unsupported Media Type" url : "http://localhost:8080/auth/admin/realms/demo/clients"
I give you my code if you can help me :
getToken(tppname) {
const data = new HttpParams()
.set('username', 'pierrecolart')
.set('password', 'root')
.set('grant_type', 'password')
.set('client_id','admin-cli');
console.log(tppname);
token: '';
tokenValue: '';
this.http
.post(
this.ROOT_URL,
data.toString(),
{headers: new HttpHeaders().set('content-type', 'application/x-www-form-urlencoded')}
)
//.map(res => res.json())
.subscribe(data => {
console.log(data);
this.token = data['access_token'];
console.log(this.token);
this.tokenValue = 'Bearer ' + this.token;
const dataPost = new HttpParams()
.set('Client ID', 's');
console.log(this.tokenValue);
this.http
.post(
'http://localhost:8080/auth/admin/realms/demo/clients',
dataPost.toString(),
{headers: new HttpHeaders().set('content-type', 'application/x-www-form-urlencoded').set('Authorization', this.tokenValue).set('Accept', 'application/json')}
).subscribe(data => {
console.log(data); })
})