为什么的android将信息发送到服务器仅适用WIFI? [英] android why sending information to server works with WIFI only?

查看:186
本文介绍了为什么的android将信息发送到服务器仅适用WIFI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过WIFI将信息发送到服务器和一切工作great.Now我想将信息发送到移动数据的服务器过了,我不知道为什么只有带WIFI的作品,随着移动数据trows异常失败连接到服务器。

I am sending information to a server via WIFI and everything works great.Now i want to send information to a server with mobile data too, and i do not know why only works with WIFI, with mobile data trows an exception of failed to connect to server.

这是失败移动数据的一部分;带WIFI完美的作品:

this is the part that fail with mobile data; with WIFI works perfectly:

int length=values.length();
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,9000);
    HttpConnectionParams.setSoTimeout(httpParams, 9000);

    HttpClient client = new DefaultHttpClient(httpParams);

    String url = saveData+"?Length="+length+"&Table="+temp;        
    HttpPost request = new HttpPost(url);
    request.setEntity(new ByteArrayEntity(values.toString().getBytes("UTF8")));        
    request.setHeader("json", values.toString());
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    // If the response does not enclose an entity, there is no need
    Log.d("test 7","test 7 last");
    if (entity != null) {
        InputStream instream = entity.getContent();
        String result =  RestClient.convertStreamToString(instream);
        Log.d("here",""+result);
        if(result.equals("success")&& ReadyOff==false){
            Ready=true;
        }else{
            Ready=false;
            ReadyOff=true;
        }
        Log.d("sent","valor de ready"+Ready);
    }

所以我做错了什么? `

so i am doing something wrong? `

推荐答案

您无法从设备的移动网络与你的服务器,除非它是来自公共互联网路由。

You cannot contact your server from the device's mobile network unless it is routable from the public Internet.

在开发机器上或以其他方式后面的NAT /防火墙上运行的服务器通常只能从本地网络/ WIFI访问。

A server running on your development machine or otherwise behind a NAT/firewall would typically only be accessible from your local network / wifi.

这篇关于为什么的android将信息发送到服务器仅适用WIFI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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