1

I'm writing an app to use an Android device to get and set data from an Access database on a local area network. I'm using HttpPost and/or HttpGet to communicate with php pages on the server which in turn communicate with the db via odbc.

It works well, but takes almost a second for each query to complete. Is there a faster way?

I'm debugging via usb on the actual device. When I access the php pages from the browser on the device, it's much faster. There is no other traffic on this network.

Thanks!

Edit: Here's the code to retrieve a dataset:

private JSONArray getData(String phpFile,ArrayList<NameValuePair> nameValuePairs){

 String result = "";
 InputStream is = null;
 JSONArray jArray=null;

try{

   HttpClient httpclient = new DefaultHttpClient();

   HttpPost httppost = new HttpPost("http://" + mServerIP + "/dressageNet/"+ phpFile);

   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

   HttpResponse response = httpclient.execute(httppost); 

   HttpEntity entity = response.getEntity();

         is = entity.getContent();

}catch(Exception e){ 
    Log.e("log_tag", "Error in http connection "+e.toString());
}

try{

    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");}
    is.close();
    result=sb.toString();

}catch(Exception e){
    Log.e("log_tag", "Error converting result "+e.toString());
    }

try{

   jArray = new JSONArray(result);

}catch(JSONException e){
   Log.e("log_tag", "Error parsing data "+e.toString());
   }

nameValuePairs.clear();
return jArray;
}
4

1 回答 1

0

以您想要的任何语言创建自定义服务器应用程序,并停止使用 http 服务器和 PHP。PHP 很慢,这会产生开销。当然,您需要实现自己的协议,但它会快得多。我在 java me 中做了类似的事情,性能比 POST/GET 好得多。

于 2011-10-01T13:10:14.597 回答