将数据从android发送到网页的最快方法

时间:2012-08-22 19:20:19

标签: php android html ajax json

我正在开发一个项目,我的Android应用将json数据发送到我的网页。截至目前,我有以下内容:

class Functions extends AsyncTask<ArrayList<NameValuePair>, Integer, Integer > {
    @Override
    protected Integer doInBackground(ArrayList<NameValuePair>... data) {
             // 1) Connect via HTTP. 2) Encode data. 3) Send data.
        try
        {
            httpclient = new DefaultHttpClient();
            HttpPost httppost = new  
  HttpPost("http:mydomain.com/save.php");  
            httppost.setEntity(new UrlEncodedFormEntity(data[0]));
            HttpResponse response = httpclient.execute(httppost);
            Log.i("postData", response.getStatusLine().toString());
        }
        catch(Exception e)
        {
            Log.e("log_tag", "Error1:  " + e.toString());
        }
      return null;      
      }

      protected void onProgressUpdate(Integer... item){
            Log.d("TestP", item[0] + " item has been processed");
      }

      protected void onPostExecute(Integer result){
            Log.d("TestP", "AsyncTask returned : " + result);
      }
}

和我的save.php文件:

$ourFileName = 'myJSON.json';
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

$json = '{"AccelX":'. $_POST['X'].'}';

var_dump(json_decode($json));
var_dump(json_decode($json, false));

fwrite($ourFileHandle, $json);

在我的网页中,我使用ajax调用从myJSON.json文件中获取数据。但是,我的网页需要一秒多的时间才能阅读。 有更快的方式发送和接收数据吗? 谢谢

0 个答案:

没有答案