服务器 - WAMP
主机 - localhost / 127.0.0.1 / 10.0.2.2(主机本地服务器的模拟器IP地址)
App - android(前端),laravel(后端)
IDE - Android Studio
我尝试过多种方法来解决这个问题,从关闭我的防火墙到创建一个同时具有命名虚拟主机和ip地址为10.0.2.2的虚拟主机。通过配置主机文件并适当地编辑http.vhosts.conf和httpd.conf文件。
我见过以下主题并且没有提供解决方案
Connection to LocalHost/10.0.2.2 from Android Emulator timed out
How to connect emulator to laravel server localhost:8000
错误看起来像这样 -
09-03 17:42:37.886 23713-23739/com.geniusesafrica.geniuses I/OpenGLRenderer: Initialized EGL, version 1.4
09-03 17:42:45.810 23713-23713/com.geniusesafrica.geniuses I/Choreographer: Skipped 476 frames! The application may be doing too much work on its main thread.
09-03 17:43:06.820 23713-23713/com.geniusesafrica.geniuses D/MainActivity: onFailure: .failed to connect to /10.0.2.2 (port 8000) after 10000ms
09-03 17:43:06.826 23713-23713/com.geniusesafrica.geniuses I/Choreographer: Skipped 1259 frames! The application may be doing too much work on its main thread.
09-03 17:43:06.829 23713-23782/com.geniusesafrica.geniuses D/FA: Connected to remote service
09-03 17:43:06.829 23713-23782/com.geniusesafrica.geniuses V/FA: Processing queued up service tasks: 1
09-03 17:43:11.867 23713-23782/com.geniusesafrica.geniuses V/FA: Inactivity, disconnecting from AppMeasurementService
以下是改造生成器 -
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://10.0.2.2:8000/api/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
我可以从机器浏览器和邮递员访问我的laravel应用程序,我可以从我的模拟器向远程地址发出请求。
在模拟器浏览器上,相同的网址会出现以下错误 -
net:ERR_NAME_NOT_RESOLVED
然后用
超时 net:ERR_CONNECTION_TIMED_OUT
任何帮助将不胜感激。