private static URLConnection reload(URLConnection uc) throws Exception {
HttpURLConnection huc = (HttpURLConnection) uc;
if (huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP
|| huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM)// 302, 301
return reload(new URL(huc.getHeaderField("location")).openConnection());
return uc;
}
运用:获取页面内容时,对于http跳https,以及多层跳转,需要做此类处理。