I got this error.
{"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null}
When try to get data from local server.
I ever got problem like this when use POST
method with Content-type: application/json
. It about CORS and I already solve this problem.
But why It happen with GET
method. Or I made some thing wrong, I try with Postman it was fine.
This is my code
get(uri) : Promise<any> {
let options = new RequestOptions({
headers: new Headers({
'Authorization' : 'Bearer ' + this.user.data.access_tokens
})
});
let end_point = this.api_server + uri;
console.log('GET : ' + end_point);
// console.log(JSON.stringify(options));
return this.http.get(end_point, options)
.toPromise()
.then(response => Promise.resolve(response.json()) )
.catch(error => Promise.reject(error) );
}
But POST
method didn’t get any error.
post(uri, data) : Promise<any> {
let options = new RequestOptions({
headers: new Headers({
'Content-Type': 'application/json',
'Authorization' : 'Bearer ' + this.user.data.access_tokens
})
});
let end_point = this.api_server + uri;
console.log('POST : ' + end_point, JSON.stringify(data));
// console.log(JSON.stringify(options));
return this.http.post(end_point, data, options)
.toPromise()
.then(response => Promise.resolve(response.json()) )
.catch(error => Promise.reject(error) );
}
ionic info
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.18.0
ionic (Ionic CLI) : 3.18.0
global packages:
cordova (Cordova CLI) : 6.5.0
local packages:
@ionic/app-scripts : 3.1.0
Cordova Platforms : ios 4.5.3
Ionic Framework : ionic-angular 3.9.2
System:
ios-deploy : 1.9.2
ios-sim : 6.1.2
Node : v6.11.0
npm : 5.5.1
OS : macOS High Sierra
Xcode : Xcode 9.1 Build version 9B55
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : legacy
Ps. http
is @angular/http