离子框架:Android模拟器无法访问主机上的服务模拟器、离子、框架、无法访问

由网友(挂在树上的骷髅)分享简介:我想实现的可用离子样品教程的http://ccoenraets.github.io/ionic-tutorial/install-ionic.html I am trying to implement the Ionic sample tutorial available at http://ccoenraets...

我想实现的可用离子样品教程的 http://ccoenraets.github.io/ionic-tutorial/install-ionic.html

I am trying to implement the Ionic sample tutorial available at http://ccoenraets.github.io/ionic-tutorial/install-ionic.html

我能够部署在Android虚拟设备的示例应用程序。然而,应用程序是无法访问驻留在笔记本电脑上的REST服务。我试图通过改变localhost改成10.0.2.2来访问该服务。我还增加了以下在config.xml

I am able to deploy sample app on Android Virtual Device. However the app isn't able to access the REST services hosted on the laptop. I am trying to access the service by changing "localhost" to "10.0.2.2". I have also added the below in the config.xml

<获得原产地=*/>

有人可以请让我知道如何解决这个问题呢?

Can someone please let me know how to resolve this issue?

推荐答案

如果您使用的是科尔多瓦的最新版本,一个你必须安装的科尔多瓦插件白名单:

If you're using one of the latest versions of cordova you must install the cordova plugin whitelist:

cordova plugin add cordova-plugin-whitelist

如果您使用的选项 - 保存将添加一个节您的 config.xml中文件:

if you use the option --save it will add a section to your config.xml file:

cordova plugin add cordova-plugin-whitelist --save

您可以阅读一些有用的信息这里有关重大变化近期科尔多瓦更新。

You can read some useful info here about important change in recent cordova updates.

您需要有这样的:

<access origin="*" />

在 config.xml中文件中设置。

如果您使用的是 Android模拟器您必须更改本地主机 10.0.2.2 和,你必须添加端口如果是从默认的不同:80

If you're using the android emulator you have to change localhost in 10.0.2.2 and, of course, you have to add the port if it is different from the default: 80.

这里。

如果您使用的是 Genymotion (比Android模拟器更好)的IP地址将是: 10.0.3.2 +端口NUM

If you're using Genymotion (much better than the android emulator) the ip address is going to be: 10.0.3.2 + the port num.

样品

Android模拟器: http://10.0.2.2:6050/api/的checkStatus Genymotion : http://10.0.3.2:6050/api/checkstatus

如果您需要调试的相关信息用于Android模拟器从命令行运行以下命令:

If you want to have debug infos for the android emulator run this from the command line:

adb -s emulator-5554 logcat

如果你运行你的Web服务器中的 IIS防爆preSS 那么你的请求无法到达主机。 这里有几个选项。我最喜欢的解决方案是使用 iisex preSS代理。 您可以安装它作为一个NPM包:

If you're running you web server in IIS Express chances are your request cannot reach the host. There are a few options here. My favourite solution is to use iisexpress-proxy. You can install it as an npm package:

npm install -g iisexpress-proxy

和运行它指定代理端口:

and run it specifying the proxy port:

iisexpress-proxy 6050 to 3000

现在你可以改变你的端口,您的仿真器:

Now you can change your port for your emulators:

Android模拟器: http://10.0.2.2:3000/api/的checkStatus Genymotion : http://10.0.3.2:3000/api/checkstatus

也许是最好的解决方法是使用一个真正的Andr​​oid设备,并与镀铬调试您的应用程序进行检查。

Probably the best solution is to use a real android device and debug your app with chrome inspect.

您必须:

启用USB调试您的移动 访问在Chrome浏览器的这个链接(镀铬://检查/#设备)

在列表中你可以打F12,看看你的设备显示什么样的错误你获得在浏览器控制台,中

Once your device show in the list you can hit F12 and see what kind of errors your getting in the browser console.

您甚至可以使用端口转发请求转发到内部服务器;基本上,你可以通过你要定义一个虚拟端口在笔记本电脑上访问您的托管服务。

You can even use the port forwarding forward request to an internal server; basically you can access your hosted services on your laptop through a virtual port you're going to define.