如何把我的Andr​​oid应用程序连接到远程Web服务器

问题描述:

我工作的一个Android应用程序。现在我请求的Web服务器,并成功获取数据。

I am working on an android app. Right now i am requesting a webserver and getting the data successfully.

现在,当我运行服务器和它的正常工作在同一网络上我的移动设备的东西。但是,当我的web服务器是一个网络为前上运行。 WLAN和Android设备的3G网络启用了我的应用程序不能发出请求。

Now the thing when i am running the server and my mobile device on the same network it's working fine. But when my webserver is running on one network for ex. WLAN and android device the Network 3G is enabled my app is not able to make the request.

所以,我怎样才能让我的web服务器的请求可见的所有不同的网络。

So how can I make my webserver request visible to all the different networks.

在Android的部分我想提出这样的改造请求到服务器。

on the android part i am making retrofit request like this to the server.

RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint("http://134.162.1.120:3000") // This is the ip of my system (just random ip for illustration purpose)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();

我时,我的PC和Android设备在同一网络上成功获取数据。
但是,当我的手机和PC是不同的网络上它没有得到连接

I am getting the data successfully when my PC and android device are on the same network. But when my phone and PC are on different network it's not getting connected

该服务器是本地PC上。

The server is on my local PC..

我相信您使用的是本地IP,而不是一个外部,这就是问题所在。替换为您的服务器的公网IP​​地址的URL。您将可以与局域网和广域网的服务器进行通信。

I believe you're using a local IP instead of an external one and that's where the problem lies. Replace the URL with your server's public IP address. You will be able to communicate with your server from both LAN and WAN.