我遇到一个奇怪的问题。在没有设置
android:targetSdkVersion
的情况下,我的http请求需要1到2秒才能完成; 但是如果设置android:targetSdkVersion ="16"
,则请求需要20到30秒才能完成!我记录了请求开始时的日志,并注意到当我启动Activity
时,系统会保持空闲状态,直到进行请求。所有的请求都在AsyncTask
中运行。以下是代码:BasicHttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, HTTP_POST_CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParameters, HTTP_POST_SOCKET_CONNECTION_TIMEOUT);
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Accept-Encoding", "gzip");
HttpClient httpClient = new DefaultHttpClient(httpParameters);
...
HttpResponse response = httpClient.execute(request);
谢谢你!