Connect to localhost from android device

怎甘沉沦 提交于 2019-12-01 13:11:03

问题


i have already search this topic and still don't know how to make it work :(
I have a SOAP web service (ASP.NET), and this address (on my localhost) is http://localhost:50473/Service1.asmx

then i have soap client on my android device, i want to connect to use service from server. Many people said that i can't connect through usb cable, and i have to connect to the same wifi network and use the internal IP.
Ok, now my laptop and android device both connect to the wifi network,
my laptop got 192.168.43.17
my android device got 192.168.43.26

So how can the device connect to the SOAP server above ?
from my device, i use 192.168.43.17:50473/Service1.asmx but no luck :(


回答1:


You need to set uses-permission - android.permission.INTERNET in AndroidManifest.xml and also test that (http://192.168.43.17:50473/Service1.asmx) url on web-browser.




回答2:


Use Http Connection

HttpClient httpclient = new DefaultHttpClient();            
HttpGet httppost = new HttpGet("http://localhost/");
HttpResponse response = httpclient.execute(httppost);              
HttpEntity ent=response.getEntity();
InputStream is=ent.getContent();



回答3:


You may have your web server listening on your loopback interface and not on your network interface. Major signs of this are:

  • Hits on 127.0.0.1 and localhost (from localhost or Android emulator) work
  • Hits on 192.168.xxx.xxx do not work, whether from localhost, LAN, or WAN

I talk more about diagnosing this and fixing this in an answer here.



来源:https://stackoverflow.com/questions/10309049/connect-to-localhost-from-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!