I have installed Cordova advanced-HTTP. Since I have to enable SSL pinning. Using HTTP client my code was working. Now I am changing my code to native Http.
Service Provider class
//MARK:- HTTP POST method
import { HTTP } from '@ionic-native/http';
postService(path: string, isLogin: boolean, serviceBody: any) {
var APIFULLURL = this.APIBASEURL + path;
//*****************Service Log ********************//
console.log("==URL ===" + APIFULLURL);
//*****************Service Log ********************//
try {
// this.http.setDataSerializer("json");
this.http.setHeader('Content-Type', 'application/json; charset=utf-8')
this.http.setHeader('Authorization', this.APIHeaderKey)
this.http.setRequestTimeout(40);
return this.http.post(APIFULLURL, JSON.stringify(serviceBody), {
'Content-Type' : 'application/json; charset=utf-8',
'Content-Encoding': 'gzip',
'Accept' : 'application/json',
'Authorization': this.APIHeaderKey,
'Access-Control-Allow-Headers': 'Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, Origin'
});
} catch (error) {
console.log(error);
alert("Error" + error)
}
}
and my calling place:
loginFRCService(value: any, loggedInBy: string): Promise<any> {
return new Promise<any>(resolve => {
//TO-DO calling web service
//login
var username: string = '';
var password: string = '';
var socialid: string = '';
var fingerprintId: string = '';
let body = {
'EmailID': username,
'LoginType': loggedInBy,
'Password': password,
'SocialMediaID': socialid,
'FingerPrintID': fingerprintId
};
this.serviceProvider.postService('Account/Authenticate', true, body).then((data : any) => {
console.log('Login Done!' + data);
resolve(data.data);
}).catch((error : any) => {
console.log("========error")
console.log(error);
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
resolve("ServiceError");
});
});
When I run the code, I got the error message.
=======error
{"line":217,"column":20,"sourceURL":"http://localhost:8080/Users/chandraat/Library/Developer/CoreSimulator/Devices/55FCEB42-21D5-43AE-B12E-68831F0E6D13/data/Containers/Bundle/Application/5981BD68-A1FD-44B4-A018-146E1C046349/dadsadsadsad.app/www/plugins/cordova-plugin-advanced-http/www/helpers.js","__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}
Please help me out.
anything wrong in my code? Please any help?