我想在asynk任務中ping服務器,但我得到sockettimeout異常,當我輸入無效的端口號,以便導致應用程序掛起。 asynk任務的Post方法從未被稱爲&應用程序不響應可能我知道它爲什麼會發生。我正在使用下面的代碼來達到這個目的。sockettimeoutexception導致應用程序掛起
private class UrlDataProvider3 extends AsyncTask<String, Void, String>
{
String ret="";
int checkStatus;
Boolean exception=false;
@Override
protected String doInBackground(String... url)
{
HttpURLConnection con = null;
try
{
Log.i("RAE", "urlData"+url[0]);
HttpURLConnection.setFollowRedirects(true);
con = (HttpURLConnection) new URL(url[0]).openConnection();
con.setRequestMethod("POST");
con.setConnectTimeout(20000);
}
catch (IOException e)
{
if(e.toString().contains("java.net.SocketTimeoutException:"))
{
log.i("Hello","Exception Occurs");
return null;
}
}
return ret;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.i("RAE"," Asyc finished");
}
返回NULL處理它' – 2014-12-06 06:30:56
不起作用 – 2014-12-06 06:31:58
catch SocketTimeoutException – 2014-12-06 06:37:01