简体   繁体   English

从android设备连接到本地主机

[英]Connect to localhost from android device

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 我有一个SOAP Web服务(ASP.NET),并且该地址(在我的本地主机上)是http:// localhost:50473 / Service1.asmx

then i have soap client on my android device, i want to connect to use service from server. 然后我在我的android设备上有soap客户端,我想从服务器连接以使用服务。 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. 许多人说我无法通过USB电缆连接,我必须连接到相同的wifi网络并使用内部IP。
Ok, now my laptop and android device both connect to the wifi network, 好的,现在我的笔记本电脑和android设备都已连接到wifi网络,
my laptop got 192.168.43.17 我的笔记本电脑有192.168.43.17
my android device got 192.168.43.26 我的Android设备获得了192.168.43.26

So how can the device connect to the SOAP server above ? 那么设备如何连接到上面的SOAP服务器?
from my device, i use 192.168.43.17:50473/Service1.asmx but no luck :( 从我的设备上,我使用192.168.43.17:50473/Service1.asmx但没有运气:(

您需要在AndroidManifest.xml中设置uses-permission- android.permission.INTERNET ,并测试Web浏览器上的(http://192.168.43.17:50473/Service1.asmx)网址。

Use Http Connection 使用Http连接

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

You may have your web server listening on your loopback interface and not on your network interface. 您的Web服务器可能在回送界面上侦听,而不是在网络界面上侦听。 Major signs of this are: 主要迹象是:

  • Hits on 127.0.0.1 and localhost (from localhost or Android emulator) work 127.0.0.1localhost (来自localhost或Android仿真器)上的点击量有效
  • Hits on 192.168.xxx.xxx do not work, whether from localhost, LAN, or WAN 无论是来自localhost,LAN还是WAN,对192.168.xxx.xxx命中都不起作用

I talk more about diagnosing this and fixing this in an answer here . 我将在此处更多地讨论诊断和修复问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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