How to solve Error Code: 0, Message HTTP failure on android - IONIC API

谁说我不能喝 提交于 2020-02-06 07:44:11

问题


When i accessed my app on the browser i have no problem accessing data from API. But when i launch it on emulator on android studio, i can´t. It pops-up a card with a ERROR CODE :0, Message Ht failure with the referent link API.

I tried to add the allow-intent, change the "localhost" on API GET request to "127.0.0.1"... and more that i don't remember.

Even the DATA received by the server side is not accessible. Right now i'm inclined to think that is a proxy related issue or a CORS problem.


回答1:


This can sometimes be caused by the emulated device looking at itself, not at your machine. Are you looking at it from the emulated device browser, the Ionic Devapp on emulated device, or built to native on the emulated device? Set any urls on the device to point to your host machine external IP, and allow open networking on the emulated device.




回答2:


Problem Solved: Basically you need to change the url on your project where you do service. Change it from localhost:3000 to 10.0.2.2:3000. The 3000is the port's number, it doesn't need to be 3000. Then you open android studio, open emulator and run it. On the litle tab right next to the android device, theres 3 dots at the end. Press those, then go to settings, and change proxy to 10.0.2.2 and the port number to the one you are using, in this case is 3000. After that it will work. Sorry for late update on the problem! For more info: why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client



来源:https://stackoverflow.com/questions/57707728/how-to-solve-error-code-0-message-http-failure-on-android-ionic-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!