【发布时间】:2015-06-10 19:49:38
【问题描述】:
private int getResponse(String url) throws Exception {
try {
URL check = new URL(url);
HttpsURLConnection connection = (HttpsURLConnection)check.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.connect();
return(connection.getResponseCode());
} catch (java.net.SocketTimeoutException e) {
return getResponse(url);
}
}
有没有比 HttpsURLConnection 更快的从 URL 获取响应代码的方法?
我从 HTTP Client Commons 尝试了 HeadMethod,但这并没有那么快。
提前致谢
【问题讨论】:
-
你不能神奇地让服务器更快。
-
connection.setRequestMethod("GET")和connection.connect()都是多余的。不要将递归用作迭代技术。