HTTP request from device to local server


#1

Hello,
I’m developping a connected application with Ionic.
So, I have a local webservice running on my computer (http://localhost:8100/xxxx)
In my app, I make call to this webservice :

  • this works when I launch the app with ionic service
  • this doesn’t work when I launch the app on my android device (with ionic run and ionic run -l)

It’d be cool if you could help me.


#2

can you even access it via phone ? I think its a problem with your network settings :smile:


#3

No, when I run it on a phone, it doesn’t work.
THat’s what I was thinking. As the host of the api requests is localhost, the phone make call locally, not on my computer.
How to call the server which is on my computer ?


#4

@ebikhafan is half right, but the problem will be because your phone is trying to access http://localhost - it doesn’t know what this is, get your IP address of your computer and replace localhost with it, this will allow your phone to access the resources.

Also look into using ionic proxy http://ionicframework.com/docs/cli/test.html


#5

yes :)) I forgot to mention :)) thanks
In linux you should just change the address to http://your-local-ip:8100/xxxx
in windows (at least for me) I had to change some network settings


#6

Hello friend, tell me how you did it to connect to your web service. Could you please teach me? is that I have been trying and I have not yet achieved it.
diargal0307@hotmail.com is my mail in case you share your code with me. Thank you.


#7

@diargal

  1. Connect the Mobile and your Computer to the same network/wifi.
  2. find your system(computer) IP.
  3. while taking the mobile build in the config file change the http://localhost:8100/ into http://YOUR_IP:8100/ eg: ( http://192.168.100.34:8100/)

Now you can access your local server form your mobile.