android为什么向服务器发送信息仅适用于WIFI?

Tob*_*iel 3 networking android

我正在通过WIFI向服务器发送信息,一切都很好.现在我也想将信息发送到带有移动数据的服务器,我不知道为什么只适用于WIFI,移动数据流程异常无法连接到服务器.

这是移动数据失败的部分; 与WIFI完美结合:

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);
    }
Run Code Online (Sandbox Code Playgroud)

所以我做错了什么?`

Chr*_*ton 5

除非可以从公共Internet路由,否则无法从设备的移动网络联系您的服务器.

在您的开发计算机上运行或在NAT /防火墙后面运行的服务器通常只能从本地网络/ wifi访问.