duanqinqian5299 2015-09-23 21:15
浏览 55

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

I have an android app that is sending data to GCM and my back end server, which is xampp in my local computer. When WI-FI is on it works like a charm. I get to send data to GCM and my server. But when I use my 3-G data on and turn off the WI-FI it doesn't deliver the data and I get "09-23 13:45:57.165 720-1055/? E/ConnectivityService﹕ net.tcp.usercfg.default not found in system properties. Using defaults 09-23 13:45:57.165 720-1055/? E/ConnectivityService﹕ net.tcp.delack.default not found in system properties." in my stack trace. What is causing this? How do I reslove this?

This the class that sends JSON to the server over 192.168....

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度