3

我正在成功地从网络服务中获取数据。但与 I-Phone 相比,所花费的时间更多。我不知道究竟是为什么。

有没有人有材料可以在android中快速获取数据(如I-Phone)......

我的代码是:

HttpResponse res = null;
        HttpParams httpParameters = new BasicHttpParams();
        int timeout1 = 1000*8;
        int timeout2 = 1000*8;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeout1);
        HttpConnectionParams.setSoTimeout(httpParameters, timeout2);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);

        //HttpClient httpClient=new DefaultHttpClient();
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("Id", user_Id));
        nameValuePairs.add(new BasicNameValuePair("kAreaNo",Chapter_Id));
        nameValuePairs.add(new BasicNameValuePair("QuestionCount",question_Count+""));
        nameValuePairs.add(new BasicNameValuePair("StartingQno",start_From+""));

        String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
        URL+=paramString;
        HttpGet post=new HttpGet(URL);

        try {

            res=httpClient.execute(post);
                            Log.i("Response=",res.getEntity().toString()+"Response aa");
            Log.i("Response=",res.getStatusLine().getStatusCode()+"Response aa");
        }
        catch (Exception e) {
            // TODO: handle exception
        }
            try{
            if (res.getEntity() != null) {
                   String retSrc = EntityUtils.toString(res.getEntity()); 
        } catch(Exception e){
                    ......
                    }
4

0 回答 0