0

I am a newbie in android app development & I have developed an android application which will start a web server and I want to request that server without providing my IP.

For example :

This is, what I type in a browser. Now localhost is not working.

("http://localhost:8000/api/items/1/");

If I provide my ipaddress instead of localhost, it works.

Is there an equivalent to localhost?

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
vk41286
  • 113
  • 1
  • 1
  • 10
  • An Android app that starts a web server? And that web server runs on the same device as the app? – greenapps Apr 09 '15 at 10:41
  • yes, that app will start server in the android device where its installed – vk41286 Apr 09 '15 at 10:42
  • 'without providing my IP. '. You do not have to provide your IP to the server. Instead you should know the IP of the server. – greenapps Apr 09 '15 at 10:42
  • 2
    Then localhost should work. And 127.0.0.1. But only if you use a browser on the same device. – greenapps Apr 09 '15 at 10:44
  • in url - if i replace localhost with my phone ip , i'm getting expected responce. but when i request with localhost , i'm getting response like webpage not found. – vk41286 Apr 09 '15 at 10:49
  • So i wanted to know , is localhost applicable for android devices also or only emulator ? and is there any other dependencies to make localhost work for android device? – vk41286 Apr 09 '15 at 10:50
  • since server is in the device , ip of the server and device ip is same – vk41286 Apr 09 '15 at 10:52
  • You have not reacted to my comment 'but only if you use a browser on the same device'. You should make clear what you are doing first. – greenapps Apr 09 '15 at 10:52
  • i'm using browser in same device – vk41286 Apr 09 '15 at 10:55
  • 2
    Well than you know my answer already. Both localhost and 127.0.0.1 should work. Did you try the latter? Why dont you react on that comment? – greenapps Apr 09 '15 at 10:59
  • maybe you can check the android device hosts file. And add `127.0.0.1 localhost` if there is not exist. – codeplay Apr 09 '15 at 14:35

0 Answers0