我正在尝试通过网络在线程上加载信息。当没有互联网时,它会冻结很长时间,然后才会引发异常或只是冻结。
有没有办法为 // FREEZES HERE 设置超时,或者在没有互联网时需要很长时间才能通过异常?他们是一种设置超时的方法response = httpclient.execute(httppost);
吗?
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://besttechsolutions.biz/projects/bookclub/getevents.php");
// FREEZES HERE or takes a long time to through exception when there is no internet
response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());