postHttp(req, data) {
let d = new Date();
const httpOptions = {
headers: new HttpHeaders({
'consumer-key': this.consumerKey,
'consumer-secret': this.consumerSecret,
'consumer-nonce': d.getTime().toString(),
'consumer-device-id': 'device id of the app',
'consumer-ip': '192.168.1.11',
})
};
const nativeHeaders = {
'Content-Type': 'application/json',
'consumer-key': this.consumerKey,
'consumer-secret': this.consumerSecret,
'consumer-nonce': d.getTime().toString(),
'consumer-device-id': 'device id of the app',
'consumer-ip': '192.168.1.11',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT',
'Accept': 'application/json'
};
return new Promise(resolve => {
console.log('Check platform: ' + this.platform.is('[quote="BesaBoldwin, post:1, topic:199500, full:true"]
postHttp(req, data) {
let d = new Date();
const httpOptions = {
headers: new HttpHeaders({
'consumer-key': this.consumerKey,
'consumer-secret': this.consumerSecret,
'consumer-nonce': d.getTime().toString(),
'consumer-device-id': 'device id of the app',
'consumer-ip': '192.168.1.11',
})
};
const nativeHeaders = {
'Content-Type': 'application/json',
'consumer-key': this.consumerKey,
'consumer-secret': this.consumerSecret,
'consumer-nonce': d.getTime().toString(),
'consumer-device-id': 'device id of the app',
'consumer-ip': '192.168.1.11',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT',
'Accept': 'application/json'
};
return new Promise(resolve => {
console.log('Check platform: ' + this.platform.is('cordova'));
if (this.platform.is('cordova')) {
this.httpNative.setDataSerializer('json');
this.httpNative.post(this.url + req, data, nativeHeaders).then(resp => {
// console.log(data.data);
let d = JSON.parse(resp.data);
// this.storeHttpData(request, d);
resolve(d);
})
.catch(error => {
});
}
else {
console.log('Data for Post: '+data);
this.http.post(this.url + req, data, httpOptions).subscribe((data: any) => {
resolve(data);
}, (err) => {
console.log('Error : ' + req, data);
});
}
});
}
if (this.platform.is('cordova')) {
this.httpNative.setDataSerializer('json');
this.httpNative.post(this.url + req, data, nativeHeaders).then(resp => {
// console.log(data.data);
let d = JSON.parse(resp.data);
// this.storeHttpData(request, d);
resolve(d);
})
.catch(error => {
});
}
else {
console.log('Data for Post: '+data);
this.http.post(this.url + req, data, httpOptions).subscribe((data: any) => {
resolve(data);
}, (err) => {
console.log('Error : ' + req, data);
});
}
});
}
Kindly help, Where am I going wrong?
1 post - 1 participant