android - 同时有几个http请求

时间:2015-10-27 03:35:21

标签: android android-asynctask httprequest httpclient background-process

我正在尝试使用httpclientAsynctask同时在同一个活动中发出多个http请求

虽然我使用.execute().get();但一切都很顺利。但我觉得请求不是后台,有时候项目挂起和错误: 项目太忙[等待] [强行关闭]

我的asynctask类:

private class get_sessions extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... arg0) {

        HttpGet post = new HttpGet(ServerName+"/?GetSessionsForAndroid");
        try {
            HttpResponse response = client.execute(post);
            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuilder sb = new StringBuilder();
            String line = "";
            while ((line = rd.readLine()) != null) {
                sb.append(line);
                break;
            }
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    protected void onPostExecute(String result1){
        try{
            JSONObject result = new JSONObject(result1);
            aktuell_date_u = result.optString("aktuell_date_u").toString();
            set_check = result.optString("set_check").toString();
            pd.cancel();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

我必须做什么,请给我一个例子

感谢

0 个答案:

没有答案