Click here to Skip to main content
15,886,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , i made an android application . this application returns data from Web applications & it works very well . unfortunately if i Use my Local Host it doesnt Work !
it gives me an error Like this :

java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused). 


i searched many websites and articles they wrote >> you should change 127.0.0.1 to
10.0.2.2 or you should change emulator setting and replace 10.0.2.2 with 127.0.0.1
...
finally i didn't succeed . i couldn't change local host & also couldn't change emulator .
i'm really sick and tired of this . i tested every thing but ...

But what will happen if i route 127.0.0.1 to 10.0.2.2 ? i think this is the only way . now i need to route ! pls tell me how can i rout it with a Command
im not expert in Commands .
Posted
Updated 29-Aug-19 8:43am
v2
Comments
Richard MacCutchan 10-Dec-14 8:31am    
127.0.0.1 is the loopback address on a network interface, so there is no point in trying to change it or redirect it. The issue you need to resolve, is to find the IP address that your service is listening on, and connect to that.
seyed mahmud shahrokni 10-Dec-14 8:37am    
i dont get it . look , my web application is in the local host 127.0.0.1 !
Richard MacCutchan 10-Dec-14 8:43am    
Is this the Android system or some other server? You need to make your question clearer.
seyed mahmud shahrokni 10-Dec-14 8:49am    
android system . pls help me if you can .
Richard MacCutchan 10-Dec-14 9:57am    
It is still not at all clear what your code is doing. Where is the web service running and what port is it connected to? How is your application trying to connect to it?

1 solution

I think i found a solution for similar problem.

1. Open command prompt and type "ipconfig".
2. Look for ip addresses under "IPv4 Address".
3. Go to web browser of Emulator or your connected device and then type:
http://192.168.56.7/login.php (i.e. http:/<ip-address>/<filename.php>)

4. If you get the response in browser of that php file then its working. Else try other ip addresses.
5. Put the working url in android class.
6. Run the application and enjoy.
 
Share this answer
 
Comments
CHill60 29-Aug-19 14:46pm    
And how do you open a command prompt in an Android system?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900