我从我的应用程序,这是尚未完成,逐字复制这种方法,但它并试图向我提供一个超时的堆栈跟踪,如果事情不顺利:
protected boolean isHttpAlive() {
boolean isHttpOk = false;
HttpURLConnection httpConnection = null;
try {
URL gurl = new URL("http://www.amazon.com/");
URLConnection connection = gurl.openConnection();
connection.setConnectTimeout(5 * 1000); // 5 seconds!
httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
isHttpOk = true;
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (httpConnection != null)
httpConnection.disconnect();
}
return isHttpOk;
}
现在,在我的测试设备(Droid的)中的一个,当有一个问题,我得到的例外 ,但只有6分36秒后,没有5秒我设置在上面的代码。
超时抛出异常的getResponseCode()
为什么?
我在想什么?