HttpURLConnection 超时设置
如果URL需要超过5秒的时间来连接,我想返回false - 使用Java怎么可能?这是我用来检查URL是否有效的代码
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);