如何把我的Andr​​oid应用程序连接到远程Web服务器 [英] How to connect my android app to the remote web server

查看:170
本文介绍了如何把我的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.

这篇关于如何把我的Andr​​oid应用程序连接到远程Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆