0

我正在尝试从 php 获取数据,我面临的问题是当数据很大时,在 android 端只收到了一半的值,而如果我只从浏览器调用 php 页面,它会给我完整的值。

这是代码,这适用于一小组数据值,它不会给出完整的结果。

调用 asyncTalk 从服务器获取数据

  DownloadMenu loadData = new DownloadMenu(AdminOperationActivity.this);
                            loadData.execute(ServerPath+"data.php");





public class DownloadMenu extends AsyncTask<String, Void, String>
     {
         ProgressDialog pd;
         Context context;

     public DownloadMenu(Context context) {
            this.context = context;
            pd = new ProgressDialog(context);   
        }
     @Override
     protected void onPreExecute(){

            pd.setMessage("Please wait Downloading Menu...");
            pd.setCancelable(false);
            pd.show();
        }
    @Override
    protected String doInBackground(String... urls) {
            // TODO Auto-generated method stub
        String output = null;
        for (String url : urls) {
            output = getOutputFromUrl(url);
        }
        return output;
    }     
    @Override
    protected void onPostExecute(String output) 
            {
                if (pd.isShowing()) {


                        pd.dismiss();
                }   
            }


    private String getOutputFromUrl(String url) {

        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                    1);
            nameValuePairs.add(new BasicNameValuePair("hid", edHotelId.getText().toString().trim()));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String responseBody = httpClient.execute(httpPost,
                    responseHandler);
            Log.d("Hotel Menu Output",responseBody);

        return url;
    }
 }
4

0 回答 0