我想在數(shù)據(jù)庫(kù)中放入一個(gè)entry。用的下面的代碼: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 "";
}這段代碼能正常運(yùn)行,現(xiàn)在當(dāng)有網(wǎng)絡(luò)連接的時(shí)候,代碼就會(huì)困在httpclient.execute(httppost, responseHandler); 大約倆分鐘。有什么方法可以實(shí)現(xiàn)檢查幾秒鐘后,如果沒(méi)有反應(yīng)的就會(huì)就catch the exceptions?
從 android 應(yīng)用程序響應(yīng)時(shí)間發(fā)送 php 查詢(xún)到服務(wù)器
幕布斯7119047
2019-03-19 17:18:32