Could someone kindly assist me? I am attempting to post user data in an object format, but it is not submitting in the desired way. Please, can someone help as I do not want it to create a new object. Here is how I would like it to be submitted:
{"birthdate":"1998","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f65604f65606a216c6062">[email protected]</a>","firstname":"jo","lastname":"david","phone":"012345678","sex":"male","identifier":"32323232","username":"joe","password":"Kdsdsdsddew32","country":"sa","affiliate":"3232"}
However, it is submitting like this:
{"user":{"birthdate":"1998","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f65604f65606a216c6062">[email protected]</a>","firstname":"jo","lastname":"david","phone":"012345678","sex":"male","identifier":"32323232","username":"joe","password":"Kdsdsdsddew32","country":"sa","affiliate":"3232"}}
Below is my code:
constructor(private http: Http, private htp: HttpClient) {
let user = {
birthdate: '',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="610b0e210b0e044f020e0c">[email protected]</a>',
firstname: 'jo',
lastname: 'david',
phone: '012345678',
sex: 'male',
identifier: '43425',
username: 'joe',
password: 'Kdsdsdsddew32',
country: 'sa',
affiliate: '3232'
};
const headers = new HttpHeaders({'Content-Type':'application/json; charset=utf-8'});
const params = new FormData();
// params.append('token', authResult.idToken);
params.append('', JSON.stringify(user));
this.htp.post(' http://192.168.66:323/test', {user}, {headers}).
subscribe(data => {
this.data = JSON.stringify(data);
});
}