Hi,
I’m trying to connect my app too my custom REST API.
Http Get and Post requests works on my android device.
With Serve my Get requests use to works with ionic 2 Beta 6 and they are still working with the call of a json file located in the www folder of the app.
But now when I try to test them with serve I log this evry time :
_body: { "isTrusted": true}
status: 200
ok: true
statusText: "Ok"
headers: {}
type: 3
url: null
My REST URL are like this for the moment and as I said they are working with my Nexus 5 connected to my wifi local network :
http://192.168.1.20/13Acc/web/api/login_check
http://192.168.1.20/13Acc/web/carte/jsonBaliseGmap
Ionic Framework Version: 2.0.0-beta.7
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
OS: Windows 7 SP1
Node Version: v4.4.3
Any idea of the problem ?
Thanks in advance !
Em… What question? Response looks well. If you want the body, you could run response.json()
method
Thank you for your answer, but perhaps the decription of my problem was unclear :
This http request works on my android device (ie for exemple I can acces to this.infosData) :
this.http.get('http://192.168.1.20/13Acc/web/carte/jsonBaliseGmap').map(res => res.json()).subscribe(
data => {
this.infosData = data.features;
....
},error=>{
console.table(error);
});
But when I run my app under serve for the same call the error is triggered and this is the error log :
_body: { “isTrusted”: true}
status: 200
ok: true
statusText: “Ok”
headers: {}
type: 3
url: null
So under serve the resquets with “http://192…” fail and I don’t know why.
The strange think is this code works on both :
this.http.get('jsonBalise.json').map(res => res.json()).subscribe(
data => {
this.infosData = data.features;
....
},error=>{
console.table(error);
});
Smells like a CORS problem.
I would suggest you to check out this article: Handling CORS issues in Ionic. It’s a bit old but might point you in the right direction. As for the success code returned for an error, it might be related to the following Angular 2 Http issue:
https://github.com/angular/http/issues/54
1 Like
Thanks a lot iignatov, the CORS article you mention solve my problem : It’s working with the use of proxies.
Ok, great, I’m glad you got it working.
i have the same exact issue but when am calling the API from the ios version . in android version it’s works like a sharm. so any help will be totally appreciated