简体   繁体   中英

Cordova android emulator - how to use local host?

I'm trying to create an application that uses rest api. The backend is on my local machine, so I've got this

127.0.0.1   api.mail.my

in /etc/hosts

In the application I've got the following:

var messageResource = $resource('http://api.mail.my/messages/:folder/:id');

which works ok, when accessing this app via browser.

But how do I make this app to access the resource, when it's being run in an emulator ( cordova emulate android )?

when you use localhost on the emulator, it refers to the ip of the emulator itself, not the one of your computer.

You have to get the local ip of your computer and use it instead of localhost or 127.0.0.1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM