Android:有没有办法为response=httpclient.execute(httppost)设置超时;

Android:有没有办法为response=httpclient.execute(httppost)设置超时;,android,Android,我正在尝试通过网络在线程上加载信息。当没有互联网时,它将冻结很长一段时间,然后引发异常或只是冻结 有没有办法设置//此处冻结的超时,或者在没有internet的情况下需要很长时间才能通过异常? 是为response=httpclient.execute(httppost)设置超时的一种方法 尝试以下方法 HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(http

我正在尝试通过网络在线程上加载信息。当没有互联网时,它将冻结很长一段时间,然后引发异常或只是冻结

有没有办法设置//此处冻结的超时,或者在没有internet的情况下需要很长时间才能通过异常? 是为
response=httpclient.execute(httppost)设置超时的一种方法

尝试以下方法

HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 30000);
HttpConnectionParams.setSoTimeout(httpParameters, 30000);

if(null == httpClient) 
httpClient = new DefaultHttpClient(httpParameters);
上面的代码通常为httpClient设置默认超时。要检查internet访问,请参阅Nomand发布的链接。

这可能会对您有所帮助,或者只需检查internet访问即可
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 30000);
HttpConnectionParams.setSoTimeout(httpParameters, 30000);

if(null == httpClient) 
httpClient = new DefaultHttpClient(httpParameters);