当WI-FI关闭时,Android向xampp服务器发送数据失败

时间:2015-09-23 21:15:12

标签: php android xampp google-cloud-messaging

我有一个Android应用程序正在向GCM和我的后端服务器发送数据,这是我本地计算机中的xampp。当WI-FI开启时,它就像一个魅力。我将数据发送到GCM和我的服务器。但是,当我使用我的3-G数据并关闭WI-FI时,它无法提供数据,我得到的是" 09-23 13:45:57.165 720-1055 /? E / ConnectivityService:在系统属性中找不到net.tcp.usercfg.default。使用默认值09-23 13:45:57.165 720-1055 /? E / ConnectivityService:在系统属性中找不到net.tcp.delack.default。"在我的堆栈跟踪中。是什么造成的?我如何重新开始呢?

这是通过192.168发送JSON到服务器的类......

class SendJSON extends AsyncTask<String, Void, String> {

        boolean failure = false;

        @Override
        protected String doInBackground(String... args) {
            try {
                try {
                    URL url;
                    HttpURLConnection urlConn;
                    url = new URL ("http://192.168.*.**/PHPserver/fipage.php");

                    urlConn = (HttpURLConnection)url.openConnection();
                    urlConn.setDoInput (true);
                    urlConn.setDoOutput (true);
                    urlConn.setUseCaches (false);
                    urlConn.setRequestProperty("Content-Type","application/json");
                    urlConn.setRequestProperty("Accept", "application/json");
                    urlConn.setChunkedStreamingMode(0);
                    urlConn.setRequestMethod("POST");
                    urlConn.connect();

                    //Create JSONObject here
                    JSONObject json = new JSONObject();
                    json.put("stuff", String.valueOf(args[0]));

                    String send=json.toString();

                    // Send POST output.
                    OutputStreamWriter os = new OutputStreamWriter(urlConn.getOutputStream(), "UTF-8");
                    os.write(send);
                    Log.i("NOTIFICATION", "Data Sent");
                    os.close();

                    BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String msg="";
                    String line = "";
                    while ((line = reader.readLine()) != null) {
                        msg += line; }
                    Log.i("msg=",""+msg);
                } catch (MalformedURLException muex) {
                    // TODO Auto-generated catch block
                    muex.printStackTrace();
                } catch (IOException ioex){
                    ioex.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("ERROR", "There is error sending");

            }
            return null;

        }

    }

0 个答案:

没有答案