我正在为 Android 编写一个应用程序。该应用程序连接到服务器以检索评论。感兴趣的代码是:
BufferedReader input = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.domain.com/personal_proj/directorydirectory/file.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.i("TEST","after httpclient.execute()");
HttpEntity entity = response.getEntity();
我在 HTC Wildfire、HTC Desire Z 中测试了这段代码,它可以工作。如果此代码在 Android 4.0+ 中执行,则永远不会到达该行
Log.i("TEST","after httpclient.execute()");
,服务器永远不会收到请求,也永远不会抛出异常。
有任何想法吗?