我正在尝试在数据库中输入一个条目。这是我正在使用的代码
String url = String.format("http://xxxxxxx/xxx/index.php?home=yes&pid=%s", pid);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
Log.e("abc", response);
return response;
} catch (ClientProtocolException es)
{
Log.e("x" , es.getMessage());
return "";
} catch (IOException e)
{
Log.e("aasx" , e.getMessage());
return "";
}
这段代码工作正常。现在当出现网络连接问题时,代码卡在
httpclient.execute(httppost, responseHandler);
了 2 分钟以上。
有没有什么方法可以只检查几秒钟,如果没有响应catch the exceptions
呢?