When i try to post a data in associative array to rest api using ionic.
Only empty data receive in server side.
Is this method is correct or suggest any other method
public login(credentials) {
let apiUrl = this.urlService.apiUrl + 'oauth/access_token';
let headers = new Headers({'Content-Type' : 'application/x-www-form-urlencoded'});
let options = new RequestOptions({
headers: headers});
var postcredn=new Array();
postcredn['username'] = "karthik@w3cert.in";
postcredn['password'] = "05550";
postcredn['grant_type'] = "password";
postcredn['client_id'] = "Outfit1548925669";
postcredn['client_secret'] = "a10620c85033ab02b582d17716cda245";
console.log('iii'+postcredn['username'] );
return new Promise((resolve, reject) => {
this.http.post(apiUrl, postcredn, options)
.subscribe(res => {
resolve(JSON.parse(JSON.stringify(res)));
console.log('json'+ JSON.stringify(postcredn));
}, (err) => {
reject(err);
public login(credentials) {
let apiUrl = this.urlService.apiUrl + 'oauth/access_token';
let headers = new Headers({'Content-Type' : 'application/x-www-form-urlencoded'});
let options = new RequestOptions({
headers: headers});
var postcredn=new Array();
postcredn['username'] = "karthik@abcde.in";
postcredn['password'] = "05550";
postcredn['grant_type'] = "password";
postcredn['client_id'] = "Outfit1548669";
postcredn['client_secret'] = "a10620c85033abd17716cda245";
console.log('iii'+postcredn['username'] );
return new Promise((resolve, reject) => {
this.http.post(apiUrl, postcredn, options)
.subscribe(res => {
resolve(JSON.parse(JSON.stringify(res)));
console.log('json'+ JSON.stringify(postcredn));
}, (err) => {
reject(err);
console.log(apiUrl);
});
});
}
} console.log(apiUrl);
});
});
}
}
Thanks in advance